|
发表于 2004-7-22 00:48:57
|
显示全部楼层
[code:1]
#include <stdio.h>
typedef
struct {
unsigned v11:8;
unsigned v12:8;
unsigned v21:16;
unsigned v22:16;
unsigned v23:16;
unsigned v31:32;
} ptrtest_t __attribute__((packed));
static ptrtest_t ptrtest;
int main(int argc, char** argv)
{
void* p1;
unsigned short* p2;
unsigned int* p3;
int i;
printf ("len of pointor:%d\n", sizeof (void*));
printf ("len of pointor:%d\n", sizeof (unsigned char*));
printf ("len of pointor:%d\n", sizeof (unsigned short*));
printf ("len of pointor:%d\n", sizeof (unsigned int*));
printf ("len of pointor:%d\n", sizeof (ptrtest_t*));
printf ("len of ptrtest_t:%d\n", sizeof (ptrtest_t));
ptrtest.v11 = 0x11;
ptrtest.v12 = 0x22;
ptrtest.v21 = 0x1433;
ptrtest.v22 = 0x1544;
ptrtest.v23 = 0x1766;
ptrtest.v31 = 0x1baa9988;
p1 = &ptrtest;
p2 = (unsigned short*)&ptrtest;
for (i=0; i<12; i++)
printf ("0x%02X ", *((unsigned char*)(p1+i)));
printf ("\n");
printf ("p1=0x%08X\n", p1);
printf ("p2=0x%08X\n", p2);
p1++;
p2++;
printf ("*(p1+1)=0x%08X\n", *((unsigned int*)p1));
printf ("*(p2+1)=0x%08X\n", *((unsigned int*)p2));
printf ("p1=0x%08X\n", p1);
printf ("p2=0x%08X\n", p2);
return 0;
}
[/code:1]
自己试试不同的值吧。 |
|