C isn't that hard: void ( *( *f[] ) () ) ()

前端 未结 13 695
名媛妹妹
名媛妹妹 2020-11-29 14:25

I just saw a picture today and think I\'d appreciate explanations. So here is the picture:

I found this confusing and wondered if such codes are ever prac

相关标签:
13条回答
  • 2020-11-29 15:31

    I happen to be the original author of the spiral rule that I wrote oh so many years ago (when I had a lot of hair :) and was honored when it was added to the cfaq.

    I wrote the spiral rule as a way to make it easier for my students and colleagues to read the C declarations "in their head"; i.e., without having to use software tools like cdecl.org, etc. It was never my intent to declare that the spiral rule be the canonical way to parse C expressions. I am though, delighted to see that the rule has helped literally thousands of C programming students and practitioners over the years!

    For the record,

    It has been "correctly" identified numerous times on many sites, including by Linus Torvalds (someone whom I respect immensely), that there are situations where my spiral rule "breaks down". The most common being:

    char *ar[10][10];
    

    As pointed out by others in this thread, the rule could be updated to say that when you encounter arrays, simply consume all the indexes as if written like:

    char *(ar[10][10]);
    

    Now, following the spiral rule, I would get:

    "ar is a 10x10 two-dimensional array of pointers to char"

    I hope the spiral rule carries on its usefulness in learning C!

    P.S.:

    I love the "C isn't hard" image :)

    0 讨论(0)
提交回复
热议问题