55 points · by ingve · 8y ago · 10 comments
That there's no difference between a const ptr and a ref at runtime is irrelevant, because there's a significant difference at compile time.
While at it, you could ditch some of the old language.
Ultimately, everything is just some place in memory, cache and/or CPU register.
This statement can confuse those who never did assembly. The fact is that CPU has only few fixed-size registers and there is no such thing like struct/array value without an address [2]. So, when you write “struct MyType v”, it will have an address on the stack, which will be loaded into the register for further access. But naming it a pointer (and a pointer to it a double pointer) is vague move. It is like naming an array a pointer too, since you have to know head address to index elements beyond it. “v” is an address at low level, but not a pointer, and while author is technically right, the terminology is mixed and thus misleading.
[1] author wrote * here, but probably meant none.
[2] unless it is small enough to be completely optimized into registers.
Edit: punctuation
/pedantic
In assembly and pre-ANSI-C, only (roughly) register sized things could be values. So you had a split of things that lived in registers and things that had to live in memory (everything that had the potential for being bigger, structs, arrays).
OOP decided that everything should be like the things in memory.
FP decided that everything should be like the things in registers.