From: ao950 AT FreeNet DOT Carleton DOT CA (Paul Derbyshire) Newsgroups: comp.os.msdos.djgpp Subject: Re: Multipal files Date: 1 Aug 1997 05:04:02 GMT Organization: The National Capital FreeNet Lines: 63 Message-ID: <5rrqo2$5co@freenet-news.carleton.ca> References: <1 DOT 5 DOT 4 DOT 16 DOT 19970727141648 DOT 54175b30 AT giasbga DOT vsnl DOT net DOT in> Reply-To: ao950 AT FreeNet DOT Carleton DOT CA (Paul Derbyshire) NNTP-Posting-Host: freenet2.carleton.ca To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Do what I do: For every module with classes other modules use, and code as well, make a .cc and a .h file. In the .h file are some parts: // foo.h // This does what-and-such #ifndef _PGD_FOO_H_ #define _PGD_FOO_H_ . . . #endif // _PGD_FOO_H_ PGD are my initials; replace them with anything you choose, but be consistent. This prevents a header being included twice. This is done by the DJGPP standard headers, as in #ifndef _DJ_STDIO_H_ and suchlike. Inside these, I put four more things. First of all, #includes needed by anything that uses the classes. #defines for any constants useful to modules using the classes. Any structs or enums similarly needed. Then the classes, with their variables and implementations of simpler functions, speed critical ones, ones that don't need to #include huge gobs of stuff for themselves that the calling routines might not use. (Otherwise compilation slows a lot. If I #included allegro.h in every module cause some function in some class used set_gfx_mode, rather than keeping the set_gfx_mode and #include to the .cc of the class...ack!) Then I have this: #ifndef _PGD_FOO_CC_ extern int bar,baz; extern double quux; #endif to declare the global variables. In the .cc I declare _PGD_FOO_CC_ and thus the variables don't get double declared. The .cc has comments like the .h, then global variables and any class variables, as in static int fooclass::foovar=0; as well as implementations of other class functions. It starts with the comments, #define _PGD_FOO_CC_, #include "foo.h" for the class definitions, #defines and everything except the global vars, any additional includes and declares it uses internally, and then the variables and code. If there are public functions not in any class, these are prototyped in the .h and the prototype is read before the function in the .cc and is available in other modules. If there are private functions of the module not in any class, they are prototyped in the .cc instead. -- .*. Where feelings are concerned, answers are rarely simple [GeneDeWeese] -() < When I go to the theater, I always go straight to the "bag and mix" `*' bulk candy section...because variety is the spice of life... [me] Paul Derbyshire ao950 AT freenet DOT carleton DOT ca, http://chat.carleton.ca/~pderbysh