【发布时间】:2010-10-07 06:59:21
【问题描述】:
感谢您对解决我以前的问题的支持。现在我正在研究自指结构。我写了以下代码:
#include <stdio.h>
int main()
{
system("clear");
struct node
{
int x;
struct node *next;
} p1;
printf(" \nthe address of node1 = %u",& p1);
printf(" \n\nthe size of node 1 = %d",sizeof( p1));
printf("\n\n the size of info part = %d",sizeof(p1.x));
printf("\n\n the size of pointer part = %ld",sizeof(p1.next));
printf("\nthe size of node is = %d\n",sizeof(struct node));
return;
}
编译后的程序很少出现警告,例如:
警告:格式“%u”需要类型 'unsigned int',但参数 2 有 输入‘结构节点*’
每次我用指针做某事时都会产生这样的警告。问题是什么?我不知道。谁能解释为什么它会发生在 Linux 上(特别是)?
我的第二个问题是,当我运行程序时,它显示结构 16 的大小,而 int 占用 4 个字节(Ubuntu 10)& 指针为 8 个字节。那为什么它显示结构大小为 16 字节?
【问题讨论】: