This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/38443] New: scoping problems with identically named identifiers
- From: "lc235951 at students dot mimuw dot edu dot pl" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 8 Dec 2008 13:34:08 -0000
- Subject: [Bug c/38443] New: scoping problems with identically named identifiers
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
The following program gives -1208725329 0 as output, and no warnings are
generated despite all warnings being turned on (-W -Wall).
#include <stdio.h>
int main()
{
int x = 0;
{
int x = x - 1;
printf("%d\n", x);
}
printf("%d\n", x);
return 0;
}
I am not sure as to the exact scoping rules employed by C in this case, and I
couldn't find a passage in the ISO C standard which would unambiguously
indicate the right version (probably because I'm not thoroughly familiar with
the standard and didn't want to read the whole document).
Even if this behaviour is correct I think there should at least be a warning.
Anyway, whatever the C standard says, it would be much more useful if the
second x were assigned -1 in this case. I actually came upon this problem in a
complicated macro expression (involving a macro inside a macro, etc.) where it
was not apparent that the names were the same. The macro would work regardless
of the names if the behaviour of GCC was as I expected it to be.
--
Summary: scoping problems with identically named identifiers
Product: gcc
Version: 4.3.2
Status: UNCONFIRMED
Severity: minor
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: lc235951 at students dot mimuw dot edu dot pl
GCC build triplet: i486-linux-gnu
GCC host triplet: i486-linux-gnu
GCC target triplet: i486-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38443