结构混乱

我有一段时间没有接触过C语言,所以我只是经历了一些概念,但却找不到任何有关结构的好资料.

任何人都可以解释

struct A
{
   int a;
   char b;
   float c;
};

这是结构A的声明或定义吗?

解决方法

这是一个宣言.

结构A;是一个forward declaration或不完整的声明.

struct A
{
   int a;
   char b;
   float c;
};

是完整的结构声明.

Example

另请查看comp.lang.c FAQ list Question 11.5

在向前声明struct之后,您可以使用结构指针,但不能取消引用指针或使用sizeof运算符或创建结构的实例.

声明后,您还可以使用struct对象,应用sizeof运算符等.

来自6.7.2.1 C11规范中的结构和联合说明符

8 The type is incomplete until immediately after the } that terminates
the list,and complete thereafter.

并从6.7.2.3标签

If a type specifier of the form
struct-or-union identifier occurs
other than as part of one of the above forms,and no other declaration
of the identifier as a tag is visible,then it declares an incomplete
structure or union type,and declares the identifier as the tag of
that type.131)
131A similar construction with enum does not exist

这不应该与extern struct A aa相混淆; v / s struct A aa = {/ *有些值* /};这是对象aa的声明和定义.

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...