Re: gcc and initialization

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Steve,

thank you for your answer.

>> I have some structures in my program, where I could save some space by
>> overlapping them.
...
>> Now I wanted to use
>> 	char *yes_no_auto[]= { "auto", "yes", "no" };
>> 	char *yes_no[]=yes_no_auto+1;
>> but that doesn't work:
...
> I think this is a more basic issue rather than a gcc issue:
>
> Initialization of non scalar values means to allocate a fixed size block
> of memory on the stack and fill it with values. This is done via the {}-
> operator .

I have to apologize - what I didn't mention was that these are static
structures, and const too.

So it's possibly more a linker question than a compiler problem - although
the problem remains to tell the compiler that these are the same things,
and should be overlapping.


> Your first version fit into this paradigma, but the second one don't.
> You have to write:
>
> char *yes_no_auto[]= { "auto", "yes", "no" };
> char *yes_no[]= {yes_no_auto[1], yes_no_auto[2]};
>
> to point the entries of your non scalar fixed size array "yes_no" to the
> already defined entries in the array "yes_no_auto".
But that still only copies the pointers, and doesn't alias the structures
themselves.

> To fill a fixed size scalar value on the stack you have to write:
...
> but then the sizeof operator will only return the size of the scalar
> value itself.
Yes, that's what I found out, too.


I thought about using something like anonymous structs or something like
that ... but that gets messy.


Thank you nonetheless.


Regards,

Phil


-- 
Versioning your /etc, /home or even your whole installation?
             Try fsvs (fsvs.tigris.org)!

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux