Complex declarations

后端 未结 8 1465
伪装坚强ぢ
伪装坚强ぢ 2020-11-30 05:03

How do I interpret complex declarations like:

int * (* (*fp1) (int) ) [10]; ---> declaration 1
int *( *( *[5])())(); --------> declaration 2

8条回答
  •  旧巷少年郎
    2020-11-30 05:48

    No, you don't need to read it loud with complex steps like "clockwise/spiral rule" and "the right rule". Why should you? You only need to know how to use it! Don't make the simple one complex.

    C declarations in fact work in a simple rule: declare as how would be used.

    Consider the code you gives out:

    int * (* (*fp1) (int) ) [10]; ---> declaration 1
    int *( *( *[5])())(); --------> declaration 2
    

    For the first declaration, this means that *(*(*fp1)(int))[int] is an int. And that's it.

    For example, you know that *(*(*fp1)(5))[0] is an int, and *(*(*fp1)(2))[9] is an int too.

    And The second declaration is incomplete. Even gcc won't know what you want to convey.

提交回复
热议问题