M
Marcus Harnisch
Hi all
Reading ISO/IEC 9899:TC3 "6.5.2.5 Compound literals", §4, I can almost
answer my own question. When using a compound literal, does the
compiler *absolutely have to* allocate an unnamed object?
Looking at assembler level, this requires extra memory access in cases
where the value could fit into an immediate.
,----
| struct s
| {
| int i;
| } S;
|
| void setS()
| {
| S = (const struct s) { // const doesn't make a difference here
| 37
| };
| }
`----
In this kind of pointless example the processor assigns S.i a value
loaded from a constant data section. Since a register is used to
(temporarily) hold S.i the actual value "37" could be implemented as
immediate value making the entire operation extrememly efficient.
Bitfield structures in particular could benefit in that case.
Thanks
Marcus
Reading ISO/IEC 9899:TC3 "6.5.2.5 Compound literals", §4, I can almost
answer my own question. When using a compound literal, does the
compiler *absolutely have to* allocate an unnamed object?
Looking at assembler level, this requires extra memory access in cases
where the value could fit into an immediate.
,----
| struct s
| {
| int i;
| } S;
|
| void setS()
| {
| S = (const struct s) { // const doesn't make a difference here
| 37
| };
| }
`----
In this kind of pointless example the processor assigns S.i a value
loaded from a constant data section. Since a register is used to
(temporarily) hold S.i the actual value "37" could be implemented as
immediate value making the entire operation extrememly efficient.
Bitfield structures in particular could benefit in that case.
Thanks
Marcus