構造体のピット
556 ワード
次に、ピット付きcodeを示します.
見た仲間は推測できる.equalまたはnot equalを印刷します.
見た仲間は推測できる.equalまたはnot equalを印刷します.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct test {
int i;
char c;
};
int main() {
struct test t1 = {0};
struct test t2 = {0, 0};
#if 1
int len;
char *p = (char *)&t2.c + 1;
printf("len = %d
", len);
#endif
if (memcmp(&t1, &t2, sizeof(struct test)) == 0) {
printf("equal
");
} else {
printf("not equal
");
}
return 0;
}