Initializing structures

Tim Josling tej@melbpc.org.au
Wed Apr 11 17:30:00 GMT 2001


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



More information about the Gcc mailing list