public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c/10696: linker problem with global variable
@ 2003-05-09  7:06 bhuang
  0 siblings, 0 replies; 3+ messages in thread
From: bhuang @ 2003-05-09  7:06 UTC (permalink / raw)
  To: gcc-gnats


>Number:         10696
>Category:       c
>Synopsis:       linker problem with global variable
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          pessimizes-code
>Submitter-Id:   net
>Arrival-Date:   Fri May 09 07:06:01 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     falls huang <bhuang@qubit-star.com>
>Release:        gcc version 3.1 20020927 ; gcc version 3.2
>Organization:
>Environment:
redhat 8.0, redhat 9.0, cygwin
>Description:
foo.h:
/*********/
int foo_global;

void f(void);
/*********/

a.c:
/*********/
#include "foo.h"

int main()
{
	foo_global = 5;
	printf("foo_global=%d\n",foo_global);
	f();
	printf("foo_global=%d\n",foo_global);
	return 0;
}
/*********/

b.c:
/*********/
#include "foo.h"

void f(void)
{
	foo_global = -1;
}
/*********/

Makefile:
all:
	gcc -c b.c
	gcc -c a.c
	gcc -o test a.o b.o
	gcc -o test1 -ansic a.c b.c
clean:
	rm -f *.o *.exe test test1 

I type "make" in console and compile the program 
without any warning and error. But I can't compile it
successfully in TurboC3.0 and Borland C.The 
foo_global that defined in foo.h is included in a.c 
and b.c, so I think the linker should report an error
when I link a.o and b.o , but gcc doesn't give any 
warning and error.
>How-To-Repeat:
Create foo.h a.c b.c makefile from my description and type "make" to compile it.
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: c/10696: linker problem with global variable
@ 2003-05-09 11:26 Joseph S. Myers
  0 siblings, 0 replies; 3+ messages in thread
From: Joseph S. Myers @ 2003-05-09 11:26 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c/10696; it has been noted by GNATS.

From: "Joseph S. Myers" <jsm28@cam.ac.uk>
To: ehrhardt@mathematik.uni-ulm.de, bhuang@qubit-star.com, 
    gcc-bugs@gcc.gnu.org, gcc-gnats@gcc.gnu.org
Cc:  
Subject: Re: c/10696: linker problem with global variable
Date: Fri, 9 May 2003 12:24:44 +0100 (BST)

 On Fri, 9 May 2003 ehrhardt@mathematik.uni-ulm.de wrote:
 
 >     Not a bug! As defined in 6.2.2 foo_global has external linkage in
 >     both translation units, hence both identifiers refer to the same object.
 
 Actually, the multiple definitions cause undefined behavior, no diagnostic
 required.  The reported behavior (allowing multiple definitions in
 different translation units, provided no more than one is initialized) is
 conventional on Unix.  If the reporter wants a diagnostic at link time,
 compile with -fno-common or link with -Wl,--warn-common (if using GNU
 binutils).
 
 -- 
 Joseph S. Myers
 jsm28@cam.ac.uk


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: c/10696: linker problem with global variable
@ 2003-05-09  9:32 ehrhardt
  0 siblings, 0 replies; 3+ messages in thread
From: ehrhardt @ 2003-05-09  9:32 UTC (permalink / raw)
  To: bhuang, gcc-bugs, gcc-prs, nobody

Synopsis: linker problem with global variable

State-Changed-From-To: open->closed
State-Changed-By: cae
State-Changed-When: Fri May  9 09:32:06 2003
State-Changed-Why:
    Not a bug! As defined in 6.2.2 foo_global has external linkage in
    both translation units, hence both identifiers refer to the same object.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=10696


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-05-09 11:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-05-09  7:06 c/10696: linker problem with global variable bhuang
2003-05-09  9:32 ehrhardt
2003-05-09 11:26 Joseph S. Myers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).