This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Initializing structures
- Subject: Initializing structures
- From: Tim Josling <tej at melbpc dot org dot au>
- Date: Thu, 12 Apr 2001 09:17:10 +1000
- CC: gcc at gcc dot gnu dot org
- Organization: Melbourne PC User Group
- References: <986959978.4125.ezmlm@gcc.gnu.org>
In COBOL, you can specify initial values at any level. Translated
to C this would look like this.
struct mystruct {
int a;
int b;
int c;
];
struct mystruct XXX = "AAABBBCCC";
In my dealings with tree.c I have tried to implement this in a
straighforward way by setting a char[] initial value to the
structure but the code generation appears to just ignore this. It
seems that the only way to do it is to have a nested structure of
initializers with the actual values only specified at the level
of elementary items.
eg the tree equivalent of
struct mystruct XXX = {123, 456,789};
It will be fairly painful to convert the string into all the
various data types. COBOL has a huge menagerie of data types such
as "numeric character format with trailing overpunched sign".
This will be a couple of days of coding I believe because
effectively I have to simulate cross platform unions.
It will probably be simpler to generate code to implement the
initial values as assignments, bracketed by 'if
(first_time_flag)' for static variables. This will not work for
externalvariables though.
My questions are
Can anyone rule in or out the possibility of getting the first
option struct mystruct XXX= "AAABBBCCC"; ?
Can anyone point me to an example where this is done in the
existing code base.
Any better ideas?
Tim Josling