Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

pointerToStruct.foo would just be equivalent to pointerToStruct->foo. No loop required.

The main problem with this is that it hides memory accesses. The offset of x.y.z.w relative to &x can be determined at compile time, so if &x is available, accessing x.y.z.w requires roughly only one load instruction. (DISCLAIMER: ABI- and compiler-dependent. One instruction is an estimate. This estimate may not be precisely true for all possible programs across all CPUs and compilers.) But x->y->z->w requires 3 pointer dereferences, even if you have x to hand. 3 load instructions and therefore 3 memory accesses. (The same disclaimer applies.) People already complain enough about the inefficiency of C++ operator overloading, and the difficulty of spotting when it occurs just by examination of the source code...

Additionally, this change wouldn't play nicely with C++ operator overloading.

I just set up my text editors to insert -> when I press <Alt-,>.



I assumed that arbitrary levels of indirection would be flattened, hence a loop. I'm not asking for this feature, I'm only arguing that C was never explicit to begin with.

For example, you cannot tell how many indirections happen in a[5][2][8] either. Every game programmer must have seen a newbie try to cast a[4][4] into a :)




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: