←back to thread

The provenance memory model for C

(gustedt.wordpress.com)
224 points HexDecOctBin | 3 comments | | HN request time: 0.877s | source
Show context
eqvinox ◴[] No.44424859[source]
Using the "register" storage class feels really alien for C code written in 2025…
replies(1): >>44428659 #
flohofwoe ◴[] No.44428659[source]
It 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

Might be useful in some situations although I currently can't think of any :)

replies(1): >>44429293 #
1. eqvinox ◴[] No.44429293[source]
I 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?

replies(1): >>44431652 #
2. flohofwoe ◴[] No.44431652[source]
I guess you're not a fan of 'const' either? ;)
replies(1): >>44433424 #
3. eqvinox ◴[] No.44433424[source]
I 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.)