I am wondering why C ++ does not define void through:
typedef struct { } void;
those. What is the meaning of a type that cannot be created, even if this setting does not generate code?
If we use gcc -O3 -S, then both of these methods produce identical assembler:
int main() { return 0; }
and
template <class T> T f(T a) { }
typedef struct { } moo;
int main() { moo a; f(a); return 0; }
It makes sense. A struct { }just takes an empty value, simple enough for optimization. Actually the weird part is that they produce different code without -O3.
You cannot, however, pull this trick simply typedef void moobecause void cannot accept any value, not even an empty one. Does this distinction have any utility?
, Haskell, , , ML, void, , , void *.