[gnu.gcc] GCC Wish: Default struct initialization

ROBERTS%UORNSRL.BITNET@MITVMA.MIT.EDU (11/25/88)

I've been working on writing a general purpose data analysis package which
includes graphics for our group here.  In the process, I've encountered some
frustrations because of restriction in the C preprocessor (not specific to
Gnu).  What I'd like to do is have some way of initializing values in a
structure at the time of declaration, i.e., like this:

struct {
  char name[16];
  int xmax=1024, ymax=1024;
  long data[1024][1024];
} spectrum1, spectrum2;

What I had in mind initially was to use a macro to expand a declaration like

graph(1024,1024) spectrum1, spectrum1;

into the above.  This would allow the users to simply #include the appropriate
header files and use things in a nice abstract fashion like

for (i=0;i==spectrum1.xmax-1;i++) ...

The inability to initialize a structure value to a default for *all* structures
of the same type makes this very difficult.  What I'm considering doing is
writing a pre-preprocessor to get the same effect (our current data analysis
package does just that).  Even so, it would require parsing the line and
expanding into several lines like

struct {
  char name[16];
  int xmax, ymax;
  long data[1024][1024];
} spectrum1, spectrum2;

spectrum1.xmax = 1024;
spectrum1.ymax = 1024;
spectrum2.xmax = 1024;
spectrum2.ymax = 1024;

Since I may have to write a pre-preprocessor anyway, it may not be a big deal,
but it sure would be nice to be able to skip this part.  Maybe something like
this could be done at the same time FSF works on allowing the size of a
variable sized array to be another element of the same structure?

Roland Roberts                        BITNET: roberts@uornsrl.bitnet
  Nuclear Structure Research Lab    INTERNET: rbr4@db2.cc.rochester.edu
  271 East River Road                   UUCP: rochester!ur-cc!rbr4
  Rochester, NY  14267                  AT&T: (716) 275-8962