Re:C uses "&" for the address-operator because 'ampersand so...
by WalterBright on Tuesday October 10, 2023 @01:17PM
(#37834792)
It 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.
Re:C uses "&" for the address-operator because 'ampersand so...
by paulddraper on Tuesday October 10, 2023 @01:21PM
(#37834847)
Not 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.
Re:C uses "&" for the address-operator because 'ampersand so...
by WalterBright on Tuesday October 10, 2023 @01:25PM
(#37834899)
Null 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.
Re:C uses "&" for the address-operator because 'ampersand so...
by brundolf on Tuesday October 10, 2023 @01:29PM
(#37834937)
Rust makes them the same too (though its type system eliminates the fallibility issue)
Re:C uses "&" for the address-operator because 'ampersand so...
by _3u10 on Tuesday October 10, 2023 @02:31PM
(#37835687)
The 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.
* Performance. Pointer access is an order of magnitude more expensive.
* Errors. Pointer access can fail (especially for NULL pointer).