我尝试了以下程序。
在Linux中,我在许多地方观察到使用
struct temp{
int ab;
int cd;
};
int main(int argc, char **argv)
{
struct temp *ptr1;
printf("Sizeof(struct temp)= %d\n", sizeof(struct temp));
printf("Sizeof(*ptr1)= %d\n", sizeof(*ptr1));
return 0;
}
输出
Sizeof(struct temp)= 8
Sizeof(*ptr1)= 8
在Linux中,我在许多地方观察到使用
sizeof(*pointer)
。如果两者是相同的,为什么使用sizeof(*pointer)
?
*ptr
。出于这个原因,我也喜欢_Static_assert(sizeof(*ptr)==sizeof(thetype_t),"You didn't finish modifying the code.");
。 - David Perek