3 ms·
> The following for [sic] declaration [sic] are then all equivalent: int i; int *ip; typeof(i) *i; _Var(_Typeof(i)) *i; What? How are "int i" and "int
by kazinator 3y ago
> The following for [sic] declaration [sic] are then all equivalent:
int i;
int *ip;
typeof(i) *i;
_Var(_Typeof(i)) *i;
What? How are "int i" and "int *ip" equivalent?
_Var(_Typeof(i)) ident strikes me as incredibly silly. The type value produced by _Typeof(i) should be directly usable as a declaration specifier, without requiring hoisting to a name.
FFS, GNU C has had a sane typeof working for years.
To bind a type to an identifier, we don't need a _Type type at all. typedef does this!
I.e. not:
_Type x = int;
but
typedef int x;
Existing, decades-old typedef is how you bind an identifier to a compile-time type value. There is no need to do this via a _Type type specifer, which then forces us to move the type we want into the initializer. We use the typeof storage class specifier, which then lets us have the type we want as another specifier, and we don't need an initializer.
This works in GNU C:
int x;
typedef typeof(x) tx; // same as typedef int tx;
The problem of declared, named containers to capture type is long solved.