このコードは、構造体が C のメモリに格納される方法を示しています。
コードは次のように記述したほうがよいでしょう。
#include <stdio.h>
#define OFFSETOF(TYPE,ELEMENT) ((size_t)&(((TYPE *)100)->ELEMENT))
typedef struct PodTag {
char c;
int i;
int j;
} PodType;
int main()
{
printf("The size of a char is %d\n", sizeof(((PodType*)0)->c));
printf("The size of an int is %d\n", sizeof(((PodType*)0)->i));
printf("The size of a PodType is %d\n", sizeof(PodType));
printf("The size of a pointer to a PodType is %d\n\n", sizeof(PodType*));
printf("If there was a PodType at location 100, then:\n");
printf(" the memory location of char c would be: %d\n",
OFFSETOF(PodType,c));
printf(" the memory location of int i would be: %d\n",
OFFSETOF(PodType,i));
printf(" the memory location of int j would be: %d\n",
OFFSETOF(PodType,j));
return 0;
}
このコードの出力は次のとおりです。
The size of a char is 1
The size of an int is 4
The size of a PodType is 12
The size of a pointer to a PodType is 8
If there was a PodType at location 100, then:
the memory location of char c would be: 100
the memory location of int i would be: 104
the memory location of int j would be: 108