gpt4 book ai didi

c - 声明和原型(prototype)的区别

转载 作者:太空狗 更新时间:2023-10-29 16:51:49 26 4
gpt4 key购买 nike

C 中的声明和原型(prototype)有什么区别?它们在哪些情况下称为声明,在哪些情况下称为原型(prototype)?

最佳答案

TL;DR;所有原型(prototype)都是声明,但并非所有声明都是原型(prototype)。

声明是标准中使用的通用术语,原型(prototype)更为具体。

引用 C11,第 6.7 章

A declaration specifies the interpretation and attributes of a set of identifiers. [...]

从 §6.7.6 开始,

Each declarator declares one identifier, and asserts that when an operand of the same form as the declarator appears in an expression, it designates a function or object with the scope, storage duration, and type indicated by the declaration specifiers.

另一方面,来自第 6.2.1 章

[....] A function prototype is a declaration of a function that declares the types of its parameters.

所以,一层,原型(prototype)是更完整的声明形式(包括参数类型)。


关于“标识符”:章节§6.4.2.1,

An identifier is a sequence of nondigit characters (including the underscore _, the lowercase and uppercase Latin letters, and other characters) and digits, which designates one or more entities as described in 6.2.1. [...]

在第 6.2.1 章中,

An identifier can denote an object; a function; a tag or a member of a structure, union, or enumeration; a typedef name; a label name; a macro name; or a macro parameter. [....]

关于c - 声明和原型(prototype)的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43781565/

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