3 ms·
I've learned something about the old days of "C" from the first commenter - e.g. the "struct { int integ; } - and then any pointer that does ptr->integ (from an
by malkia 13y ago
I've learned something about the old days of "C" from the first commenter - e.g. the "struct { int integ; } - and then any pointer that does ptr->integ (from anything) would access it as an integer".
- jhallenworld 13y agoI 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.