3 ms·
oh no. this is DEFINITELY a place where zig made a GOOD change away from c. when a value is dereferenced, having a consistent left to right dereferencing make
by throwawaymaths 2y ago
oh no. this is DEFINITELY a place where zig made a GOOD change away from c.
when a value is dereferenced, having a consistent left to right dereferencing makes sense.
for example, in c, without looking up the order of operations how confident are you that you know what is going on in the following:
foo = **bar[10]
- wat10000 2y agoIf prefix * bugs you, C has a suffix deference operator as well, `[0]`. (Yes, C programmers will probably hunt you down if you do this, but it does work.)
- throwawaymaths 2y agothis is not just a preference but a practical matter, esp. for reading nd checking other People's code. did you solve the puzzle at the end with high confidence?
- wat10000 2y agoYou mean `foo = *bar[10]`? That’s equivalent to `bar[10][0][0]`, i.e. the array element access is done first, then the retrieved element is dereferenced twice. I’m quite confident in this, but I’m a systems programmer working in C++, so that’s my bread and butter.
- deleted 2y ago[deleted]
- throwawaymaths 2y agoit's hard to disambiguate from bar[0][0][10]...
- wat10000 2y agoSure, I see your point and suffix does seem like the better option. But for people who do a lot of C, it’s not an issue.