428,600 Members | 1,214 Online
Need help? Post your question and get tips & solutions from a community of 428,600 IT Pros & Developers. It's quick & easy.

# casting to char*,

 P: n/a On Windows XP, unsigned integers are 32 bits. Partition the bits of the unsigned integer C into 4 8-bit chunks like so: C = XRGB. Then unsigned char* p = &C; Does p[0] = X; ? p[1] = R; ? p[2] = G; ? p[3] = B; ? or p[0] = B; ? p[1] = G; ? p[2] = R; ? p[3] = X; ? Sep 15 '06 #1
8 Replies

 P: n/a Since you are on a little-endian machine, I believe the answer is #2. On Fri, 15 Sep 2006, vsgdp wrote: On Windows XP, unsigned integers are 32 bits. Partition the bits of the unsigned integer C into 4 8-bit chunks like so: C = XRGB. Then unsigned char* p = &C; Does p[0] = X; ? p[1] = R; ? p[2] = G; ? p[3] = B; ? or p[0] = B; ? p[1] = G; ? p[2] = R; ? p[3] = X; ? Sep 15 '06 #2

 P: n/a vsgdp posted: On Windows XP, unsigned integers are 32 bits. Depends on your compiler. Partition the bits of the unsigned integer C into 4 8-bit chunks like so: C = XRGB. Then unsigned char* p = &C; Does p[0] = X; ? p[1] = R; ? p[2] = G; ? p[3] = B; ? or p[0] = B; ? p[1] = G; ? p[2] = R; ? p[3] = X; ? Depends how much crack you smoke, because your code has no basis in C++. -- Frederick Gotham Sep 16 '06 #3

 P: n/a On Windows XP, unsigned integers are 32 bits. Partition the bits of the unsigned integer C into 4 8-bit chunks like so: C = XRGB. Then unsigned char* p = &C; Does p[0] = X; p[1] = R; p[2] = G; p[3] = B; ? or p[0] = B; p[1] = G; p[2] = R; p[3] = X; ? Easy enough to check: unsigned int C = 1; cout << sizeof(C) << endl; unsigned char* p = (unsigned char*)&C; cout << "[0]" << (int)p[0] << "\t"; cout << "[1]" << (int)p[1] << "\t"; cout << "[2]" << (int)p[2] << "\t"; cout << "[3]" << (int)p[3] << endl; For option 1, the expected output would be 4 [0]0 [1]0 [2]0 [3]1 For option 2: 4 [0]1 [1]0 [2]0 [3]0 (Further testing with C = 256, C = 256 * 256, and C = 256*256*256 would add to the confidence you get running this.) Michael P.S. On my machine, with my compiler, I get option 2. Sep 16 '06 #4

 P: n/a On Sat, 16 Sep 2006 00:19:27 GMT, Frederick Gotham

 P: n/a Frederick Gotham

 P: n/a Jens Theisen wrote: Frederick Gotham vsgdp posted: >>On Windows XP, unsigned integers are 32 bits. Depends on your compiler. Uh? On SysV ABI compliant system such as Linux it doesn't. Are you sure that in the Windows world, there is no such standard? There is not. MS publishes an API for system calls, but have no requirements for apps (or compilers). Bo Persson Sep 16 '06 #7