[ gcc@xxxxxxxxxxx removed from list ] Zoltán Kócsi wrote: > I have various constants. If I define them in a header file like this: > > static const int my_thing_a = 3; > static const int my_thing_b = 12345; > > then everything is nice, if I use them the compiler knows their value > and uses them as literals and it doesn't actually put them into the > .rodata section (which is important because I have a lot of them and > code space is at premium). > > Now these things are very closely related, so it would make the program > much clearer is they could be collected in a structure. That is: > > struct things { int a; int b; }; > > and then I could define a global structure > > const struct things my_things = { 3, 12345 }; > > so that I can refer them as my_things.a or my_things.b; > > The problem is that I do not want to instantiate the actual "things" > structure, for the same reason I did not want to instantiate the > individual const int definitions. So, I tried the GCC extension of > "compound literals" like this: > > #define my_things ((struct things) { 3, 12345 }) > > int func( int x ) > { > if ( x ) > return my_things.a; > else > return my_things.b; > } > > If I compile the above with -O2 or -Os, then if the target is AVR or > x86_64 then the result is what I expected, func() just loads 3 or 12345 > then returns and that's all. There is no .rodata generated. > > However, compiling for the ARM generates the same function code, but it > also generates the image of "things" in the .rodata segment. Twice. Even > when it stores 12345 separatelly. The code never actually references > any of them and they are not global thus it is just wasted memory: Works for me, arm-linux-gnueabi-gcc -S t.c -O2 generates: .file "t.c" .text .align 2 .global func .type func, %function func: @ args = 0, pretend = 0, frame = 0 @ frame_needed = 0, uses_anonymous_args = 0 @ link register save eliminated. ldr r3, .L5 cmp r0, #0 moveq r0, r3 movne r0, #3 bx lr .L6: .align 2 .L5: .word 12345 arm-linux-gnueabi-gcc (GCC) 4.4.0 20080618 Andrew.