gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 15:35:30 25 4
gpt4 key购买 nike

代码如下:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com