This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
middle-end/10875: There is no multiple symbol definition error or warning for global symbols
- From: jmortensen at cfl dot rr dot com
- To: gcc-gnats at gcc dot gnu dot org
- Date: 19 May 2003 22:02:53 -0000
- Subject: middle-end/10875: There is no multiple symbol definition error or warning for global symbols
- Reply-to: jmortensen at cfl dot rr dot 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: