middle-end/10875: There is no multiple symbol definition error or warning for global symbols

[email protected]
Newsgroups gmane.comp.gcc.prs
Message-ID <20030519220253.3946.qmail__45571.6372387998$1053381876@sources.redhat.com>
>Number:         10875
>Category:       middle-end
>Synopsis:       There is no multiple symbol definition error or warning for global symbols
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Mon May 19 22:06:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Jose Mortensen
>Release:        gcc 3.2.1
>Organization:
>Environment:
debian linux 2.4.19, HPUX B.10.20 (gcc 2.95.2)
>Description:
Two globals with the same name but different types declared in different files are resolved by the linker as one variable without an error or warning message. 

1.	Conflicting types should give an error. I don’t know if this is actually allowed  in ansi-C 
2.	Looks like Ansi-C takes this kind of code as declaration if it has already been defined, but would be handy if it could at least give a warning.

A simplified example is given below:

// file1.c
 
#include <stdio.h>

int* var;

void other_function(){
   var = NULL;
}


// file2.c

#include <stdio.h>
void other_function();

int var;

int main(int argc, char** argv)
{
   var = 1;
   other_function();
   printf("%d\n", var);
}

>How-To-Repeat:
just cut and paste the code given above and run gcc

> gcc file1.c file2.c
>Fix:
coding carefully
>Release-Note:
>Audit-Trail:
>Unformatted:
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.