From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17153 invoked by alias); 8 Dec 2008 13:35:30 -0000 Received: (qmail 16816 invoked by uid 48); 8 Dec 2008 13:34:08 -0000 Date: Mon, 08 Dec 2008 13:35:00 -0000 Subject: [Bug c/38443] New: scoping problems with identically named identifiers X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "lc235951 at students dot mimuw dot edu dot pl" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2008-12/txt/msg00734.txt.bz2 The following program gives -1208725329 0 as output, and no warnings are generated despite all warnings being turned on (-W -Wall). #include 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