a puzzle of struct in gcc (4.6.0 20110212).

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,
I build following code in gcc(4.6.0 20110212), the result of print is:
  temp1 = 0x11111111
  temp2 = 0x11111111
  temp3 = 0x22222211

howerer, in gcc(Ubuntu 4.4.3-4ubuntu5), the result of print is:
  temp1 = 0x22111111
  temp2 = 0x22221111
  temp3 = 0x22222211

 Why temp1 equal to temp2 in gcc 4.6, but not in gcc 4.4?

Thanks

////////////////////////////////////////////////////////
//test code
////////////////////////////////////////////////////////
#include <stdio.h>

int main(int argc, char* argv[])
{
	struct {
		int u1;
		int u2[2];
	} date1 = {0x00000000, {0x11111111, 0x22222222}};

	struct {
		int u1;
		int u2;
		int u3;
	} date2 = {0x00000000, 0x11111111, 0x22222222};

	int temp1 = *(int*)((char*)(&date1.u2)+1);
	
	printf("temp1 = 0x%x\n", temp1);

	int temp2 = *(int*)((char*)(&date1.u2)+2);
	
	printf("temp2 = 0x%x\n", temp2);

	int temp3 = *(int*)((char*)(&date2.u2)+3);
	
	printf("temp3 = 0x%x\n", temp3);

	return 0;
}


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux