Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!ut-sally!husc6!cmcl2!brl-adm!adm!gea@Iago.Caltech.EDU From: gea@Iago.Caltech.EDU (Gary Ansok) Newsgroups: comp.lang.c Subject: External variable declarations Message-ID: <8056@brl-adm.ARPA> Date: Fri, 26-Jun-87 16:10:37 EDT Article-I.D.: brl-adm.8056 Posted: Fri Jun 26 16:10:37 1987 Date-Received: Sat, 27-Jun-87 10:36:37 EDT Sender: news@brl-adm.ARPA Lines: 32 At least according to K&R (p. 77), there is no need for fancy #define's to make sure that global variables are declared and initialized properly. header.h: struct foo { ... }; extern int var1; extern struct foo var2; file.c: #include "header.h" int var1 = 42; struct foo var2 = { ... }; The disadvantage is that the type of a variable is duplicated in two places (some mismatches will be detected by the compiler); however, you get cleaner (and easier to write and understand) code which is, I think, less easy to misdeclare (what happens if two or zero modules define __GLOB__? -- not that this is damnfoolproof). You can also spread the initializations around among modules if you think of a global variable as "owned" by one module and "used" by other modules (if your program works that way). Like many other things in programming, especially C programming, this is something where we can argue for hours. But I thought I'd present a case with no messy #defines or #ifs. Gary Ansok gea@romeo.caltech.edu -- or -- ansok@scivax.arpa