gpt4 book ai didi

C 声明符理解

转载 作者:行者123 更新时间:2023-12-05 00:45:19 27 4
gpt4 key购买 nike

我正在阅读 C99 ISO 标准中的声明符,但我很难理解以下段落:

5 If, in the declaration ”T D1”, D1 has the form

    identifier

then the type specified for ident is T.

6 If, in the declaration “T D1”, D1 has the form

    ( D )

then ident has the type specified by the declaration “T D”. Thus, a declarator in parentheses is identical to the unparenthesized declarator, but the binding of complicated declarators may be altered by parentheses.

最佳答案

您省略了前面的重要段落:

4 In the following subclauses, consider a declaration

    T D1

where T contains the declaration specifiers that specify a type T (such as int) and D1 is a declarator that contains an identifier ident. The type specified for the identifier ident in the various forms of declarator is described inductively using this notation.

所以,当我们进入第 5 和第 6 段时,我们知道我们正在考虑的声明中包含一些我们标记为 ident 的标识符。例如,在 int foo(void) 中,identfoo

第 5 段说如果声明“T D1”只是“T ident”,它将 ident 声明为 T 类型。

第 6 段说,如果声明 “T D1” 只是 ”T ( ident)”,它还声明 identT 类型。

这些只是为声明的递归规范建立基本情况。第 6.7.5.1 条继续说,如果声明“T D1”是 ”T * some-qualifiers D” 和没有 * 和限定符的相同声明,”T D”将声明 ident 为“some-derived-type T”(如“array of T ”或“指向T”的指针),那么带有*和限定符的声明将ident*声明为“some-派生类型 some-qualifiers 指向T”的指针。

例如,int x[3]x 声明为“3 个 int 的数组”,所以 6.7.5.1 中的这条规则告诉我们“int * const x[3]x 声明为“3 个指向 int 的 const 指针的数组”——它需要“3”的数组”,它必须是先前派生的,并向其附加“const 指针”。

类似地,第 6.7.5.2 和 6.7.5.3 条告诉我们将数组和函数类型附加到带有括号(用于下标)和后缀括号的声明符。

关于C 声明符理解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64065994/

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