4 ms·
Using the "register" storage class feels really alien for C code written in 2025…
by eqvinox 1y ago
Using the "register" storage class feels really alien for C code written in 2025…
- flohofwoe 1y agoIt has a slightly different meaning now, instead of hinting to the compiler that the variable should be placed in a register it now means that it is illegal to take the address of the variable (e.g. cannot create a pointer from it): https://www.godbolt.org/z/eEYf5c59f https://www.godbolt.org/z/eEYf5c59f Might be useful in some situations although I currently can't think of any :)
- eqvinox 1y agoI mean, yeah, but that function is really only an aid for the programmer in self-enforcing that rule; the compiler already knows whether the address of the variable is taken anywhere, and behave as is useful if it isn't taken anywhere… Doesn't feel particularly valuable to have that "help" from the compiler against "accidentally" taking the address of a variable… I mean, how do you even accidentally do that?
- flohofwoe 1y agoI guess you're not a fan of 'const' either? ;)
- eqvinox 1y agoI am a fan of "const", because it is useful in expressing API constraints and behavior. Contrast against putting "register" on a function parameter being useless because either it's passed by value, then it's a copy anyway and register is meaningless to the caller, or it's a pointer, in which case it again does nothing because you already have a pointer (and something somewhere is very confused.)