#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int main()
{
struct emp
{
struct address
{
int a;
};
struct address a1;
};
}
此代码显示警告:-
警告:声明未声明任何内容(默认启用)
下面的代码没有显示任何警告
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int main()
{
struct emp
{
struct address
{
int a;
}a1;
};
}
为什么仅在第一个代码中显示“警告”?
编译器显示警告的原因是它没有看到类型变量的名称address
您定义为emp
结构,即使你do使用声明某事address
在下一行,但我猜编译器不够聪明,无法弄清楚这一点。
正如您所展示的,这会产生一个警告:
struct emp {
struct address {}; // This statement doesn't declare any variable for the emp struct.
struct address a1;
};
但不是这个:
struct emp {
struct address {} a1; // This statement defines the address struct and the a1 variable.
};
Or this:
struct address {};
struct emp {
struct address a1; //the only statement declare a variable of type struct address
};
The struct emp {}
不显示任何警告,因为此语句不在结构定义块内。如果您确实将其放入其中之一,那么编译器也会显示警告。下面会出现两个警告:
struct emp {
struct phone {};
struct name {};
};
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)