C declaration syntax is fairly convoluted …
Which brings me to my question regarding casting syntax,
Simple types are easy enough, just put the type in brackets.
But what about types like,
int (*2Dap) [5]; or double (*fp) (double, double);
I guessing here, the rule is to just strip away the identifier (plus the semicolon) of a normal variable declaration and put it in brackets.
So, int (*2Dap) [5]; becomes ( int (*) [5] ) and char * str; becomes just (char *)
Is this a general rule?
As so typedef, your new “type” would be what is your “variable” in your typedef declaration,
eg. typedef double (*twoINoneOUT) (double, double); “twoInoneOUT” would be your new “type”.
Correct??
Just wanted to clarify. I know I’m unlikely to even need to cast these – could save me from having to typedef unnecessarily though.
Right. This declares a variable called
x:The type of the variable is
int (*)[5], and you could cast to that type using the cast(int (*)[5]).Also correct. This declares a type alias called
t:Syntactically,
typedefappears in the same place as a storage class specifier likestatic.