Article View: gnu.gcc.bug
Article #604typedef and object name spaces
From: John Riedl
Date: Mon, 18 Sep 1989 21:08
Date: Mon, 18 Sep 1989 21:08
26 lines
1376 bytes
1376 bytes
gcc allows typedef's to be used to declare variables in an inner scope
with the same name as a typedef from the outer scope. This seems to
agree with the letter of the ansi standard (I only have K&R's new
book), but has the problems that it only works the first time (after
that the new variable replaces the typedef in the namespace) and that
the code is unlikely to compile under other C compilers. I have
attached a short program exhibiting the behaviour that caught me. I
suggest that this is a common mistake for a beginner to make,
especially because the name spaces for objects and struct/union tags
are separate. The Sun C compiler complains about the declaration,
which helps the programmer. At the least, gcc should complain in
-pedantic mode.
Thanks,
John Riedl
{ucbvax,decvax,hplabs}!purdue!riedl -or- riedl@cs.purdue.edu
-------
typedef int X;
main()
{
X X; /* this works */
X Y; /* X has been redefined, so this fails */
}
---------
Technical Details
Message-ID:
<8909182108.AA16868@medusa.cs.purdue.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!CS.PURDUE.EDU!riedlShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!CS.PURDUE.EDU!riedl From: riedl@CS.PURDUE.EDU (John Riedl) Newsgroups: gnu.gcc.bug Subject: typedef and object name spaces Message-ID: <8909182108.AA16868@medusa.cs.purdue.edu> Date: 18 Sep 89 21:08:30 GMT Sender: daemon@tut.cis.ohio-state.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 26