4 ms·
The thing is, the `->` operator in C is completely unnecessary. `.` can be used instead. The compiler can distinguish by looking to see if the lvalue is a point
by WalterBright 3y ago
The thing is, the `->` operator in C is completely unnecessary. `.` can be used instead. The compiler can distinguish by looking to see if the lvalue is a pointer or a value.
The result makes it much easier to refactor code. Ever try replacing a value with a pointer in C? Arrghh.
- guenthert 3y agoRedundancy is a good thing. It helps humans to detect errors and they need all the help they can get.
- paulddraper 3y agoI think it is debatable on whether struct property access and pointer access should appear the same. * Performance. Pointer access is an order of magnitude more expensive. * Errors. Pointer access can fail (in particular, the NULL pointer).
- WalterBright 3y agoIt may be debatable, but in D we've used it for 20 years and problems with it have yet to crop up. And indeed, it makes refactoring code far easier.
- paulddraper 3y agoNot directly to syntax, but D null pointer safety is weird IMO. It checks array access bounds, but segfaults for null pointers. Seems an odd choice, and there are multiple discussions of people saying the same.
- WalterBright 3y agoNull pointers are automatically checked by the hardware (seg fault). Adding another runtime check is redundant. Yes, I know, adding a huge fixed offset to the pointer can push it past the null protected pages.
- brundolf 3y agoRust makes them the same too (though its type system eliminates the fallibility issue)
- _3u10 3y agoThe stack is not some magical location in RAM that is faster, and in any case you can have a pointer to the stack. It's super common to define a struct on the stack and then pass a pointer to an init function to initialize the value that is on the stack. Sometimes pointers are faster because you don't have to copy the entire struct. What largely determines the performance of values vs. pointers is whether that location in RAM is cached, and whether you need to allocate memory on the heap.
- wruza 3y agoI wanted this (and few more dozens of things) most of the time when I still wanted to write C. Good times.