public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/38443] New: scoping problems with identically named identifiers
@ 2008-12-08 13:35 lc235951 at students dot mimuw dot edu dot pl
2008-12-08 19:43 ` [Bug c/38443] " pinskia at gcc dot gnu dot org
0 siblings, 1 reply; 2+ messages in thread
From: lc235951 at students dot mimuw dot edu dot pl @ 2008-12-08 13:35 UTC (permalink / raw)
To: gcc-bugs
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug c/38443] scoping problems with identically named identifiers
2008-12-08 13:35 [Bug c/38443] New: scoping problems with identically named identifiers lc235951 at students dot mimuw dot edu dot pl
@ 2008-12-08 19:43 ` pinskia at gcc dot gnu dot org
0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-12-08 19:43 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pinskia at gcc dot gnu dot org 2008-12-08 19:40 -------
On the trunk we get:
t.c: In function 'main':
t.c:7: warning: 'x' is used uninitialized in this function
Which is correct. x in the inner scope comes alive right after the = sign.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
Target Milestone|--- |4.4.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38443
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-12-08 19:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-12-08 13:35 [Bug c/38443] New: scoping problems with identically named identifiers lc235951 at students dot mimuw dot edu dot pl
2008-12-08 19:43 ` [Bug c/38443] " pinskia at gcc dot gnu dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).