Gabest said:
Oh, and is this legal or a bug?
No, this is legal (but *very* confusing).
Can I also write (X) blah, X()blah, ()X
blah, (X blah) then, just for fun?
No, its no fun at all.
The "thing" being declared can be put inside a pair of parenthesis, because
sometimes it is needed ...
To declare a pointer to a function, you actually need to write
return_type (*Fptr)(param_type);
to show that the star goes with Fptr and not with the return type. If you
write it like
return_type * FPtr(param_type)
it's suddenly a function returning a pointer, not a pointer to a function
....
So, to make it "simple" you are just always allowed to put the name you
declare inside a pair of parenthesis. I guess it was just to difficult to
specify exactly when it could be needed!
Now we can write our declarations above as:
return_type (*Fptr)(param_type); // pointer to function returning a value
and
return_type* (Fptr)(param_type); // function returning a pointer to a
value
Unfortunately this rule makes this ok, and meaning the same:
type variable;
type (variable);
type(variable);
but the last one looks terribly much like these
class_name(initial_value);
function_name(formal_parameter);
The language rules simply say that if you can't tell, it is to be seen as a
declaration.
Bo Persson