Path: utzoo!attcan!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!usc!apple!snorkelwacker!bloom-beacon!eru!luth!sunic!mcsun!hp4nl!phigate!ehviea!leo From: leo@ehviea.ine.philips.nl (Leo de Wit) Newsgroups: comp.lang.c Subject: Re: extern Message-ID: <824@ehviea.ine.philips.nl> Date: 7 Jul 90 16:29:39 GMT References: <111254@linus.mitre.org> <910@bjcong.bj.co.uk> <277@taumet.com> <16994@haddock.ima.isc.com> <1990Jul5.044045.1534@acc.stolaf.edu> Reply-To: leo@ehviea.UUCP (Leo de Wit) Organization: Philips I&E Eindhoven Lines: 51 In article <1990Jul5.044045.1534@acc.stolaf.edu> hannum@haydn.psu.edu (Charles Hannum) writes: | |In article <16994@haddock.ima.isc.com> karl@haddock.ima.isc.com (Karl Heuer) writes: | | In article <277@taumet.com> steve@taumet.UUCP (Stephen Clamage) writes: | >The usual trick is then to do something like this: | > #define EXTERN extern | | In rebuttal, I'd like to mention that many of us find this grotesque, and | prefer to use | /* header.h */ | extern int foo[20]; | extern double bar; | | /* something.c */ | #include "header.h" | int foo[20]; | double bar = 3.0; | which is also completely portable, doesn't require preprocessor games, and | allows the objects to have initializers (this can sometimes be done with your | method too, but it makes it even uglier). Since the defining source file also | includes the header, you can't get them out of sync. | | |Some of us also find your method grotesque, because we have to alter the |definition in *two* places rather than one if we change it. Apparently another mix-up of declarations (which I feel belong in header files) and definitions (which I feel belong in source files). If you find this grotesque, why make a difference for function declarations/definitions? Be consequent and have the body of the function conditionally included in the header file ... I'd also like to know how the 'extern-trick-advocates' handle multiple include files; each would need its own EXTERN macro (and guess what mysterious failures happen if you misspell them in the source file). And then I'm not even talking about nested include files. [] |"... preprocessor games, ..."? It's not a game. It's a perfectly ligitimate |use of the C preprocessor. If we weren't supposed to use it, it wouldn't be |included (based C's minimalist philosophy). Whether or not this is a perfectly legitimate use of the C preprocessor is not the issue. I'm sure the Obfuscated C Code Contest will give us again lots of perfectly legitimate programs, showing us how NOT to code. Leo. #define EXTERN GROTESQUE