A
artifact.one
Hi.
I'm working on a program that has one file of its source
code generated by a script that reads a colon delimited data
file and creates some C arrays as output. Now, in this data
file, some pieces of data refer to other pieces of data and
therefore, in these generated structures, there are pointers
to other generated data structures. The script is quite
brain dead. It doesn't try to order the data structures so
that the ones at the bottom of the chain of dependencies are
declared first (this might not even be possible, given the
data).
I thought a solution to this might be to (gasp!) put
declarations such as these at the top of the file:
extern const struct mkf_type *pretypes_execldep[];
extern const struct mkf_type *pretypes_cpjlib[];
And then the script will declare the actual structure later
in the same file:
const struct mkf_type *pretypes_cpjlib[] = {
&type_dynamicldep,
&type_dynamicldepx,
};
This way, I avoid any 'variable is undeclared at this point'
errors.
The trouble is, this gives the data structures external
linkage, which I really don't want. Making the array
declaration 'static' would, as far as I know, cause
undefined behaviour because of the previous 'extern'
declaration but I can't see that I can get rid of the
'extern' declaration given the ordering problem (some
structures refer to other structures that will not have been
declared yet if the 'extern' declaration is removed).
I realise this may sound like total gibberish, so be gentle
please. I've not completely grasped the intricacies
(horrors?) of the humble C compiler yet.
Any help would be appreciated.
MC
I'm working on a program that has one file of its source
code generated by a script that reads a colon delimited data
file and creates some C arrays as output. Now, in this data
file, some pieces of data refer to other pieces of data and
therefore, in these generated structures, there are pointers
to other generated data structures. The script is quite
brain dead. It doesn't try to order the data structures so
that the ones at the bottom of the chain of dependencies are
declared first (this might not even be possible, given the
data).
I thought a solution to this might be to (gasp!) put
declarations such as these at the top of the file:
extern const struct mkf_type *pretypes_execldep[];
extern const struct mkf_type *pretypes_cpjlib[];
And then the script will declare the actual structure later
in the same file:
const struct mkf_type *pretypes_cpjlib[] = {
&type_dynamicldep,
&type_dynamicldepx,
};
This way, I avoid any 'variable is undeclared at this point'
errors.
The trouble is, this gives the data structures external
linkage, which I really don't want. Making the array
declaration 'static' would, as far as I know, cause
undefined behaviour because of the previous 'extern'
declaration but I can't see that I can get rid of the
'extern' declaration given the ordering problem (some
structures refer to other structures that will not have been
declared yet if the 'extern' declaration is removed).
I realise this may sound like total gibberish, so be gentle
please. I've not completely grasped the intricacies
(horrors?) of the humble C compiler yet.
Any help would be appreciated.
MC