3 ms·
I similar trick: eliminate need for '.' by declaring things inside an array of size 1: struct { int n; } z[1]; Now you can say z->n. This is useful because st
by jhallenworld 13y ago
I similar trick: eliminate need for '.' by declaring things inside an array of size 1: struct { int n; } z[1]; Now you can say z->n. This is useful because structs are usually passed by reference. Why should code accessing members of a local variable struct look any different than code dealing with a pass-by-reference struct?
- nly 13y agoThat's one reason why C++ has actual references in addition to pointers.
- CUViper 13y agoCute! However, if you really want complete equivalence between locals and struct* parameters, you might prefer something like "struct { int n; } _z, * const z = &_z;". There's a slight difference of types when using your array version, so things like sizeof(z) and &z don't mean the same thing as when used on struct* parameter.