3 ms·
I really prefer that '.' and '->' remain separate, because it makes it immediately clear when a potentially expensive pointer derefence is happening: x = a
by flohofwoe 3y ago
I really prefer that '.' and '->' remain separate, because it makes it immediately clear when a potentially expensive pointer derefence is happening:
x = a->b->c->d->e;
...is a pointer-hunting-nightmare / potential cache-miss-galore.
x = a.b.c.d.e;
...no problem, the whole chain is resolved at compile time into a single offset and results in at most one memory access.
x = a.b.c->d.e;
...makes it immediately clear that c->d is a pointer access and everything else isn't.
PS: ...and of course C++ messed this simple rule up with the introduction of references.
- nuancebydefault 3y agoWhen stepping up from C to C++, it feels ultimately unlogical to use an ampersand to indicate a reference in a declaration, while in an assigment or actual parameter it means address of. Where they out of special chars?