读书人

sizeof计算函数外宣言结构体被告知结构

发布时间: 2012-09-27 11:11:17 作者: rapoo

sizeof计算函数外声明结构体被告知结构体未声明
具体代码如下:
#include <stdio.h>
struct aa {
int bb;
};
int main(){
int sz=sizeof(aa);
printf("aa=%d\n",sz);
return 0;
}

报错如下:
headertest.c:6: error: ‘aa’ undeclared (first use in this function)
headertest.c:6: error: (Each undeclared identifier is reported only once
headertest.c:6: error: for each function it appears in.)

恳求高人指教,多谢!

[解决办法]
需要如下这样声明,否则你每次都要这样struct aa去引用了。
typedef struct{
int bb;
}aa;

读书人网 >C语言

热点推荐