c/10697: linker problem with global variable
bhuang@qubit-star.com
bhuang@qubit-star.com
Fri May 9 08:08:00 GMT 2003
>Number: 10697
>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:
More information about the Gcc-bugs
mailing list