Path: utzoo!attcan!uunet!samsung!usc!zaphod.mps.ohio-state.edu!sdd.hp.com!ucsd!ucbvax!EN.ECN.PURDUE.EDU!wscott From: wscott@EN.ECN.PURDUE.EDU (Wayne H Scott) Newsgroups: comp.lang.c Subject: Initilization of global structures Message-ID: <9005020423.AA05715@en.ecn.purdue.edu> Date: 2 May 90 04:23:02 GMT Sender: daemon@ucbvax.BERKELEY.EDU Lines: 57 I am having some problems with a program I am writing. This might be very simple but I can't figure it out. I have several global arrays that hold constant information as arrays of structures. (weapon data, race data, ...) I also have a global array of player information that has some arrays of number of weapons. The problem I am having is that I want the compiler to be able to figure out how many weapons are defined in the structure and use that number to define the player structure. Perhaps an example will help. The following code does not work on my machine but it explains what I want. [file=globals.c] #define MAXNUM 5 struct weapon { char *name; /* etc */ }; struct weapon wstats[] = { "knife", "sword" /* etc ... */ }; #define NUMWEAP (sizeof(wstats)/sizeof(struct weapon)) /* or perhaps int NUMWEAP = (sizeof(wstats)/sizeof(struct weapon)); */ struct person { char *name; int weaps[NUMWEAP]; }; struct person party[MAXNUM]; [file=main.h] extern struct weapon { char *name; } wstats[]; #define NUMWEAP (sizeof(wstats)/sizeof(struct weapon)) extern struct person { char *name; int weaps[NUMWEAP]; } party[]; The globals.c file works but I can't get the main.h file correct so that other files can see the information. If someone can figure out what I am trying to say and knows a solution please send me mail. Sorry if this is trivial. _______________________________________________________________________________ Wayne Scott | INTERNET: wscott@en.ecn.purdue.edu Electrical Engineering | BITNET: wscott%ea.ecn.purdue.edu@purccvm Purdue University | UUCP: {purdue, pur-ee}!en.ecn.purdue.edu!wscott _______________________________________________________________________________ "To iterate is human. To recurse, divine."