Re: extern



On Wed, 20 Jul 2005 13:39:13 +0100, in comp.lang.c , Lawrence Kirby
<lknews@xxxxxxxxxxxxxxx> wrote:

>On Wed, 20 Jul 2005 12:03:08 +0100, Mark McIntyre wrote:
>
>> On Tue, 19 Jul 2005 21:43:12 -0500, in comp.lang.c , Jack Klein
>> <jackklein@xxxxxxxxxxx> wrote:
>>
(of two files with int a; in them)

>>>If you compile these two source files and combine them into a single
>>>executable, you produce undefined behavior.
>>
>> You sure? The second behaves exactly as if it had been declared
>> extern int a;
>
>Both have identical (external) linkage but their behaviour in terms of
>whether they create a definition is different.
>
>As such both a.c and b.c contain a definition of a so linking them
>produces undefined behaviour.

Really? The standard makes it pretty clear that in the absence of a
storage class specifier, a file-scope object is considered to be
extern. And FWIW I can't recall a compiler that behaves otherwise than
to consider two such declarations to be synonyms. I confess, my
initial thought was the same as yours, but closer reading of the
standard deconvinced me. Can you point me to the actual section that
confirms your view?


--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
.



Relevant Pages

  • when linked with IHhlpapi.lib, get unknown _GetAdaterAddressess()
    ... class to compile with other source files to generate an executable. ... int getHwInfo(void); ... Debug/ipHwIntf.exe: fatal error LNK1120: 1 unresolved externals ...
    (microsoft.public.win32.programmer.networks)
  • Re: reading file backwards and parsing
    ... >typecasting line 62 as an int. ... doesn't compile clean. ... This positions you 1 character before the '\n'. ... Undefined behavior in C89 because memset is assumed to return an int ...
    (comp.lang.c)
  • Re: c++ compiler error
    ... program that does not compile or run properly. ... is the problem function a function or a member function? ... >required int variables themselves, yet it still complains. ... You have undefined behavior because a, b, c, and d have unspecified ...
    (alt.comp.lang.learn.c-cpp)
  • Re: extern
    ... >>If you compile these two source files and combine them into a single ... >>executable, you produce undefined behavior. ... > extern int a; ...
    (comp.lang.c)
  • Re: Allocated memory
    ... Just because it's undefined behavior doesn't mean it won't compile. ... int main ... > struct myStruct mStruct; ...
    (comp.lang.cpp)