4 ms·
>The type of %1 is %struct.MyType* and not %struct.MyType [1]. In the case of references and pointers, clang actually transforms them into double pointers. This
by wruza 8y ago
>The type of %1 is %struct.MyType* and not %struct.MyType [1]. In the case of references and pointers, clang actually transforms them into double pointers. This is the first indicator that lvalues (all these C++ variables are lvalues) are translated into pointers.
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
- gpderetta 8y agoEven if the structure is not small enough, unless the address does not escape (which can be common for local objects), the compiler is free to split it up in its constituents and only store some (or none) of its constituents in memory, which doesn't even need to be contiguous. I think this optimization is called scalar replacement of aggregates. /pedantic