c - 紧接在函数名/参数之后但在方括号之前声明的结构。有人可以解释这个 C 语法吗?

标签 c function struct function-definition

代码如下:

A_output(message) 
 struct msg message;
{

}

我以前从未见过这样的语法。该结构定义在做什么?这只是在参数字段中指定“消息”的“类型”的另一种方式吗?那么,它和这个是一回事吗?:

A_output(struct msg message) 
{

}

最佳答案

这个

A_output(message) 
 struct msg message;
{

}

是现在不允许使用的函数定义的旧语法,因为该函数未声明返回类型。早期默认返回类型是 int

至于这样的函数定义

void A_output(message) 
 struct msg message;
{

}

那么它就是一个带有标识符列表的有效函数定义。

来自 C 标准(6.9.1 函数定义)

6 If the declarator includes an identifier list, each declaration in the declaration list shall have at least one declarator, those declarators shall declare only identifiers from the identifier list, and every identifier in the identifier list shall be declared. An identifier declared as a typedef name shall not be redeclared as a parameter. The declarations in the declaration list shall contain no storage-class specifier other than register and no initializations.

关于c - 紧接在函数名/参数之后但在方括号之前声明的结构。有人可以解释这个 C 语法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28973227/

相关文章:

c - C 中 sizeof 运算符中的参数

javascript函数应用程序验证问题

database - Golang DB反/序列化方法(数据库/sql之上的sqlx)

pointers - Golang 结构问题指向父结构方法

c - 为什么我在 C 代码中使用 x->y = z 而不是 x.y = z?

c - 通过tcsetattr(fd.....)设置终端属性时,fd可以是stdout还是stdin?

C程序忽略包含sizeof的if语句

c - 使用 Lua C Api 从索引中获取数组值

javascript - JS : Can I call a function with same scope as caller or do macro-like behavior

c - 将任意数量的参数传递给函数