Is a pointer to an array of unknown size incomplete?

后端 未结 2 530
感动是毒
感动是毒 2021-01-06 20:11

3.9/6 N3797:

[...]

The type of a pointer to array of unknown size, or of a type defined by a typedef declaration to be an array of unkno

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-06 20:35

    I think this wording is defective. In your code:

     int (*a)[];
    

    the type of a is actually complete. The type of *a is incomplete. It seems to me (as dyp says in comments) that the intent of the quote was to say that there is no way that later in the program, *a will be an expression with complete type.

    Background: some incomplete types can be completed later e.g. as suggested by cdhowie and dyp:

    extern int a[];
    int b = sizeof a;  // error
    int a[10];
    int c = sizeof a;  // OK
    

    However int (*a)[]; cannot be completed later; sizeof *a will always be an error.

提交回复
热议问题