Xref: utzoo comp.lang.c:38067 news.software.b:7413 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!samsung!uunet!airs!ian From: ian@airs.UUCP (Ian Lance Taylor) Newsgroups: comp.lang.c,news.software.b Subject: Re: Redeclaration of Variables extern/static Summary: It's illegal according to ANSI C Keywords: scope, ibm, c news Message-ID: <1243@airs.UUCP> Date: 9 Apr 91 04:18:57 GMT References: <^R+_H3-@uzi-9mm.fulcrum.bt.co.uk> Reply-To: airs!ian@uunet.uu.net (Ian Lance Taylor) Followup-To: comp.lang.c Organization: AIRS, Waltham, MA Lines: 37 In article <^R+_H3-@uzi-9mm.fulcrum.bt.co.uk> igb@fulcrum.bt.co.uk (Ian G Batten) writes: >C News, amongst other things, has declarations of ``extern int foo;'' in >either a header or towards the top of a file, and later has ``static int >foo;''. > >Can anyone quote chapter and verse as to the legality of this? The ANSI C standard 3.1.2.2: ``... If the declaration of a file scope identifier for an object or a function contains the storage-class specifier *static*, the identifier has internal linkage. If the declaration of an identifier for an object or a function contains the storage-class specifier *extern*, the identifier has the same linkage as any visible declaration of the identifier with file scope. If there is no visible declaration with file scope, the identifier has external linkage. ... If, within a translation unit, the same identifier appears with both internal and external linkage, the behavior is undefined.'' So in the case you mention, the behavior is undefined. This means that according to the standard, the compiler can do anything it pleases, specifically including ``terminating a translation.'' Of course, in this particular case that's pretty tacky. Still, in the long run it would probably be better to change the code (I have no idea what that would involve). -- Ian Taylor airs!ian@uunet.uu.net uunet!airs!ian First person to identify this quote wins a free e-mail message: ``But this machine chews all kinds of paper into a thick porridge that no chemist in the world, however skilled a criminal he may be, can read.''