Path: utzoo!utgpu!water!watmath!dalcs!garfield!john13 From: john13@garfield.UUCP (John Russell) Newsgroups: comp.lang.c Subject: Re: extern Keywords: extern Message-ID: <4430@garfield.UUCP> Date: 23 Jan 88 05:09:25 GMT References: <17428@topaz.rutgers.edu> <7123@brl-smoke.ARPA> <4405@garfield.UUCP> <7150@brl-smoke.ARPA> Reply-To: john13@garfield.UUCP (John Russell) Distribution: na Organization: Memorial University of Newfoundland, St. John's Lines: 34 In article <7150@brl-smoke.ARPA> gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) writes: >In article <4405@garfield.UUCP> john13@garfield.UUCP (John Russell) writes: >-file 1 - >-int fou; >[I assume "foo" was intended] Not the point. This exact situation happened to me (with different variable names of course). DAMN tough to track down! Luckily I noticed the typo shortly after it occurred (after running the program once). >-file 2 - >-extern int foo; >-foo = 1; >-then at least some compilers will run this properly (no warnings even). >PLEASE don't do this. A compiler is not obliged to make this example >"work". No kidding :-). But I do think it's important to know of this peculiar behaviour, which could easily cause hard-to-find errors when using "extern". The original article seemed to be asking *how* extern storage was treated, and this example shows how the compiler doesn't always behave as you would assume under an "ideal" model of C. This was the C on our 4.3BSD system. I was shocked that the linker didn't complain at all that I was extern'ing a variable, then referring to it, when it didn't exist in any other module. John -- "Am I dreaming, or was there a show on this weekend called 'Jimmy the Greek: Live at the Apollo'?" -- David Letterman