🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c.moderated
Article #2204

Re: "extern" and function declarations

#2204
From: news
Date: Fri, 08 Mar 1996 23:02
26 lines
1276 bytes
In article <4hmslm$b3l@solutions.solon.com> glaurent@worldnet.net writes:

>I've got a question here : what if the same above declaration is made
>in two (or more) files, compiled seperately then linked together ?

>ie, in file a.c :

>extern int i = 1;

>...

>and in file b.c :

>extern int i = 2;

>If I understand correctly what you've said, both of these declarations
>will reserve space, and give i a value. My question is, what decides
>which value will actually be "used", and what happens to the "duplicate"
>space ?

Such a program is in error, and what happens is undefined.  Some
implementations will detect this error at link time and complain,
other will not.  I know of one implementation that will only detect
this some of time.

A valid program will only have one definition in all the modules.
Technical Details
Message-ID: <4hqeas$1i4@solutions.solon.com>
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
References: <4hdqjq$8pr@solutions.solon.com> <4hmslm$b3l@solutions.solon.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
From: news@Thinkage.On.CA
Newsgroups: comp.lang.c.moderated
Subject: Re: "extern" and function declarations
Date: 8 Mar 1996 17:02:52 -0600
Organization: Thinkage Ltd.
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <4hqeas$1i4@solutions.solon.com>
References: <4hdqjq$8pr@solutions.solon.com> <4hmslm$b3l@solutions.solon.com>
NNTP-Posting-Host: solutions.solon.com