Are the "complex float" and "floating complex" valid?

My question is this:

Are the "complex float" and "float complex" valid C?

Both seem accepted without gcc warnings.

+8
c
source share
2 answers

complex - the macro from complex.h, which expands into a specifier of type _Complex . This behaves like all other type specifiers, for example int, bool, double . For all type specifiers that belong to the same group, you can combine them in different orders. This is indicated in C11 6.7.2, my emphasis is:

The statement must contain at least one qualifier type qualifier in each declaration , and in the list of qualifier-qualifiers in each structure declaration and type name. Each list of type specifiers must be one of the following multisets (separated by commas when there is more than one multiset per element); type specifiers can occur in any order , possibly mixed with other declaration specifiers.

This is followed by a list of valid groups of type specifiers, where we find

  • float _Complex
  • double _Complex

This means that any permutation of qualifiers in the same group is wonderful.


To take another example, there is a group

  • unsigned long long , or unsigned long long int

This 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; ... 

All this means the same thing.

+6
source share

Yes. In the general case, the order of "type words" at the beginning of the declaration does not matter:

 static const unsigned long int x = 42; 

coincides with

 long const int unsigned static x = 42; 

Reference: C99, 6.7.2 / 2

[...] type specifiers can occur in any order, possibly mixed with other declaration specifiers.

(Both float and _Complex are type specifiers.)

+5
source share

All Articles