- 论坛徽章:
- 1
|
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- //#include <stddef.h>
- #pragma pack(8)
- #define SETBIT(a,i) ((a)[(i) / 8] |= (1 << (7 - (i) % 8)))
- typedef struct _testStru{
- char chArr[8];
- char *pCh;
- }testStru;
- int main()
- {
- testStru* test=(testStru *)calloc(1, sizeof(testStru));
- printf("test.chArr1 is %x.\n", test->pCh);
- SETBIT(test->chArr, 65); //故意内存越界
- printf("test.chArr2 is %p.\n", test->pCh);
- printf("test.chArr3 is %p.\n", test->pCh);
- return 0;
- }
复制代码 只是模拟的我们程序中的一个用例,第二个printf打印的值竟然是没有SETBIT前的值,第三个printf才变成更新后的值,求解释。。。。
我在一个linux server上用gcc version 4.1.2 20080704 (Red Hat 4.1.2-52)竟然模拟不出来。。。 |
|