My question is simply this:
Are both "complex float" and "float complex" valid C?
Both seem to be accepted without warnings by gcc.
complex
is a macro from complex.h which expands into the type specifier _Complex
. This behaves as all other type specifiers, for example int, bool, double
. For all type specifiers belonging to the same "group", you can combine them in various orders. This is specified by C11 6.7.2, emphasis mine:
At least one type specifier shall be given in the declaration specifiers in each declaration, and in the specifier-qualifier list in each struct declaration and type name. Each list of type specifiers shall be one of the following multisets (delimited by commas, when there is more than one multiset per item); the type specifiers may occur in any order, possibly intermixed with the other declaration specifiers.
Then follows a list of valid groups of type specifiers, where we find
float _Complex
double _Complex
Meaning that any permutation of the specifiers in the same group is fine.
To take another example, there is a group
unsigned long long
, orunsigned long long int
Which gives us the following possible combinations:
unsigned long long x;
long unsigned long y;
long long unsigned z;
or
unsigned long long int a;
unsigned long int long b;
unsigned int long long c;
int unsigned long long d;
long unsigned long int e;
long long unsigned int f;
long long int unsigned g;
long unsigned int long h;
...
These all mean the same thing.
Yes. In general, the order of "typey words" at the beginning of a declaration doesn't matter:
static const unsigned long int x = 42;
is the same as
long const int unsigned static x = 42;
Reference: C99, 6.7.2/2
[...] the type specifiers may occur in any order, possibly intermixed with the other declaration specifiers.
(Both float
and _Complex
are type specifiers.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With