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;