69,371
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
struct s1
{
int a1;
char a2;
char *a3;
long unsigned int a4;
double a5;
};
struct s2
{
struct s1 b1;
struct s2 *b2;
};
struct s2 s;
#define FORMAT "%08x %02x %08x %08x %08x%08x, %08x"
#define VARIABLE(x) (unsigned int)(x)->b1.a1, (unsigned int)(x)->b1.a2, \
(unsigned int)(x)->b1.a3, (unsigned int)(x)->b1.a4, \
*(unsigned int*)(unsigned char*)&(x)->b1.a5, \
*(unsigned int*)(((unsigned char*)&(x)->b1.a5) + 4), (unsigned int)(x)->b2
int test(void)
{
struct s2 c;
struct s2 d = {};
struct s2 e = {{}, };
struct s2 f = {{0, 0, 0, 0, 0.0}, 0};
printf("local: struct s2 c: "FORMAT"\n", VARIABLE(&c));
printf("local: struct s2 d = {}: "FORMAT"\n", VARIABLE(&d));
printf("local: struct s2 e = {{}, }: "FORMAT"\n", VARIABLE(&e));
printf("local: struct s2 f = {{0, 0, 0, 0, 0.0}, 0}: "FORMAT"\n", VARIABLE(&f));
printf("global: struct s2 s: "FORMAT"\n", VARIABLE(&s));
return 0;
}
int main()
{
return test();
}
struct s2 s;
memset(&s, 0, sizeof(struct s2));