【问题标题】:What is the meaning of statement below that the declared type shall not be incomplete type下面声明的类型不能是不完整类型的语句是什么意思
【发布时间】:2013-09-15 00:09:08
【问题描述】:

C 标准规定:

如果对象标识符的声明是暂定的 定义并具有内部链接,声明的类型不应是 不完整的类型

“声明的类型不能是不完整的类型”是什么意思?

【问题讨论】:

    标签: c definition linkage


    【解决方案1】:

    这意味着你不能拥有:

    static int arr[]; // This is illegal as per the quoted standard.
    int main(void) {}
    

    数组arr是暂定定义的,类型不完整(缺少有关对象大小的信息),还具有内部链接(static 表示arr 具有内部链接)。

    而以下(在文件范围内),

    int i; // i is tentatively defined. Valid.
    
    int arr[]; // tentative definition & incomplete type. A further definition 
               // of arr can appear elsewhere. If not, it's treated like
               //  int arr[] = {0}; i.e. an array with 1 element.
               // Valid.
    

    有效。

    【讨论】:

    • 没有人编译器没有给出错误..这就是我首先想到的
    • 您是否执行严格的标准合规性?当我执行gcc -Wall -pedantic -std=c99 t.c 时,我得到t.c:1:12: error: array size missing in ‘arr’ t.c:1:12: warning: ‘arr’ defined but not used [-Wunused-variable]。 gcc 默认启用许多扩展,可能无法满足 C 标准的所有要求。使用上述选项,它会产生更好的诊断结果。
    猜你喜欢
    • 1970-01-01
    • 2014-08-27
    • 2015-12-17
    • 1970-01-01
    • 2022-01-02
    • 2017-01-09
    • 1970-01-01
    • 2011-12-19
    • 2021-01-03
    相关资源
    最近更新 更多