Path: utzoo!attcan!uunet!mcvax!hp4nl!philmds!leo From: leo@philmds.UUCP (Leo de Wit) Newsgroups: comp.sys.atari.st Subject: Re: MWC/CSD bug? Message-ID: <909@philmds.UUCP> Date: 4 Jan 89 19:13:10 GMT References: <5440009@hplsla.HP.COM> Reply-To: leo@philmds.UUCP (Leo de Wit) Organization: Philips I&E DTS Eindhoven Lines: 55 In article <5440009@hplsla.HP.COM> andyc@hplsla.HP.COM (Andy Cassino) writes: |I'm having trouble with the -VCSD option in Mark Williams C, version 3.05. | |The problem was discovered trying to debug a complex GEM application, |but can be demo'd with some very simple files: | |foo.h - local include file that defines global variable "foo" |mod1.c - source module which #includes foo.h |main.c - another source module which #includes foo.h | |The program compiles and runs when I compile with "cc mod1.c main.c". | |However, with "cc -VCSD mod1.c main.c" there will be a complaint |similar to: | | "ld: foo redefined in main.c" It looks as if you try to define foo twice; that is not allowed in C, although some compilers may be a bit more tolerant than I 8-). Your foo.h entry for "foo" probably looks something like: int foo; The linker is confused and doesn't know which storage to use: that created by the "mod1", or that created by the "main" definition. The correct way is never to use include files for definitions, only for external declarations (and symbol definitions and typedefs). Short lesson: An include file (module header file) is used to export the global definitions of one module source file, or for common used definitions (project / application wide, or standard header files). The file is included by the defining module as well as by the modules that use the external references. Don't use it for storage, either program or data. End of short lesson ( 8-). The best strategy (I think) is to declare foo in foo.h and define it in one of the modules: typically the one that defines operations upon it (note the difference between definition and declaration; I use the K&R terminology). So if you put (mutatis mutandis) into foo.h: extern int foo; and in main.c: int foo; your problem should be solved. Yes, I know there are some compilers that don't like a extern reference and a definition of a variable in the same file; they're just broken. Hope this helps - success! Leo.