In practice, nobody uses a "clockwise/spiral rule" to read C declarations; they typedef complex declarations into bite-sized components. C declarations are hardest to understand when they involve (1) "arrays"† of "arrays" of "arrays", (2) function pointers, and (3) multiple layers of indirection. In systems and networking code and in most application code, (1) "multi-level arrays" are uncommon, and they're uncommon i…
The "Clockwise/Spiral Rule" in C
21–30 of 49 posts
Re: The "Clockwise/Spiral Rule" in C
#22Re: The "Clockwise/Spiral Rule" in C
#23Re: The "Clockwise/Spiral Rule" in C
#24 char *(*fp)(int)
I see that it matches the pattern returntype *(*function)(args)
It's the "* (* )()" that one sees all at once, and that signifies "this is a function pointer".This actually reminds me of some research where kids are asked to trace the direction of interlocked gears. They start by looking at each one, but soon they move to more general strategies. Edit - this is the one, in case anyone is curious: Dixon, J. A., & Bangert, A. S. (2002). The prehistory of discovery: precursors of representational change in solving gear system problems. Developmental Psychology, 38(6), 918.
Re: The "Clockwise/Spiral Rule" in C
#25Earlier quoted context omitted.
I think it works if you treat all the [] as a single token. foo is a 3x4 two dimensional array of pointers to int.
You can construct a rule along those lines that would work (though just taking all the [] at once doesn't suffice), but it ends up being precisely equivalent to the right-left rule, so I don't really see the point.
Re: The "Clockwise/Spiral Rule" in C
#26In practice, nobody uses a "clockwise/spiral rule" to read C declarations; they typedef complex declarations into bite-sized components. C declarations are hardest to understand when they involve (1) "arrays"† of "arrays" of "arrays", (2) function pointers, and (3) multiple layers of indirection. In systems and networking code and in most application code, (1) "multi-level arrays" are uncommon, and they're uncommon i…
Re: The "Clockwise/Spiral Rule" in C
#27This is why I like S-Expressions
Re: The "Clockwise/Spiral Rule" in C
#28In practice, nobody uses a "clockwise/spiral rule" to read C declarations; they typedef complex declarations into bite-sized components. C declarations are hardest to understand when they involve (1) "arrays"† of "arrays" of "arrays", (2) function pointers, and (3) multiple layers of indirection. In systems and networking code and in most application code, (1) "multi-level arrays" are uncommon, and they're uncommon i…
I like types. I do have a question though: Why do you call it "sig_t" as opposed to "sig_h" or something. Based on its positional appearance, it's pretty clear that it's a type. Or does t stand for something else?
Re: The "Clockwise/Spiral Rule" in C
#29Earlier quoted context omitted.
I like types. I do have a question though: Why do you call it "sig_t" as opposed to "sig_h" or something. Based on its positional appearance, it's pretty clear that it's a type. Or does t stand for something else?
It's a POSIX convention to indicate that it's a typedef.
Re: The "Clockwise/Spiral Rule" in C
#30Earlier quoted context omitted.
It's a POSIX convention to indicate that it's a typedef.
User code built against POSIX should never use the _t suffix; POSIX explicitly puts *_t into the reserved namespace ( http://pubs.opengroup.org/onlinepubs/007904975/functions/xsh... ), meaning that future revisions may add arbitrary type names of that form, which will break your code if you use the same name and include POSIX headers.