ANSI-C grammar - array declarations like [*] et alii

后端 未结 3 1138
别跟我提以往
别跟我提以往 2021-02-14 08:54

The ANSI C grammar from -link- give me the following rules for array declarations:

 (1) | direct_declarator \'[\' type_qualifier_list assignment_expression \']\'         


        
3条回答
  •  温柔的废话
    2021-02-14 09:41

    My K&R2nd (which covers and includes the ANSI standard) does not seem to say anything about [*] either in the text, or in the standard itself. Nor can I make the official grammar in the standard accept that syntax.

    It may be related to K&R c (though I don't seem to recall it), may have been a common extension, or have been a proposal that ultimately didn't make the standard.

    I would assume it makes the dimension of the array explicitly unspecified. But I'm just guessing.


    Hmm...gcc accepts

    #include 
    
    void f(int s, int a[*]);
    
    int main(void){
      int a[2] = {0};
      f(2,a);
      return 0;
    }
    
    void f(int s, int a[]){
      int i;
      for (i=0; i

    in ansi, c89 and c99 mode; issuing no warnings even with -Wall. Note that it did not like the [*] syntax in the function definition. Adding -pedantic made it complain about the [*] syntax in c89 and ansi modes, but it continued to accept in in c99 mode.

提交回复
热议问题