4 ms·
Previously: https://news.ycombinator.com/item?id=12775735 https://news.ycombinator.com/item?id=12775735 Apparently the Spiral Rule is not entirely correct.
by theoh 8y ago
Previously: https://news.ycombinator.com/item?id=12775735 https://news.ycombinator.com/item?id=12775735
Apparently the Spiral Rule is not entirely correct.
- mehrdadn 8y agoIn C the type of a variable is "variable-centric" rather than "type-centric": it's denoted by syntax akin to the one you would use to use the variable. So if you have int (*arr)[2] that means "if you dereference arr, the expression represents an array of 2 elements". So, for example, if you want a pointer to a function that returns a pointer to an array of two elements, how do you denote it? You'd go step-by-step based on how you would use it: int a[2] int (*f)[2] int (*(*fp)())[2] Once you understand this, the typing syntax should make sense, and you see that any description like spirals or whatever misses the big picture.
- burfog 8y agoSo how do I declare a function pointer for a function that takes two arguments and returns a value, all of which are function pointers of that same type?
- mehrdadn 8y agoI can't tell if this is a rhetorical question or not, but you can't have recursive typedefs in C.
- burfog 8y agoI can't tell either. :-) The grammar seems to prevent recursive typedefs, but I've never seen it spelled out that you can't have them. This has caused me trouble on occasion. I can't even seem to solve this with gcc's non-standard __typeof__ extension. I was halfway expecting to crash or hang the compiler.
- mehrdadn 8y agoI mean if you take the grammar to be part of the official language specification and you believe it prohibits recursive typedefs then isn't that sufficient? It seems a bit like saying it causes you trouble on occasion that they never explicitly spelled out that 'deftype' isn't a synonym for 'typedef'? I would've assumed that if something is not valid in the grammar then it's not valid in the language described by it.
- burfog 8y agoWell the hope is that somehow I'm misunderstanding the grammar... because there simply must be a way to do this. How can the language committee leave this flaw unfixed?
- mehrdadn 8y ago> there simply must be a way to do this. Why? This seems completely baseless. > How can the language committee leave this flaw unfixed? Same way many languages like C++, C#, Java, VB etc. left this "flaw" unfixed.
- toast0 8y agovoid* </s>
- mamon 8y agoMain issue here is that such syntax is write-only. Every time you read this expression later you have to go through the mental gimnastics you've just described to understand it.
- mehrdadn 8y agoI'm not endorsing it!
- andreareina 8y agoaka, "declaration follows use"