ANSI typedef rules

Robert Shaw rjshaw at ramius.llnl.gov
Fri Mar 15 12:34:40 AEST 1991


In regards to ANSI C, what (if anything) does the standard say about 
an identifer that is in the scope of both a typedef and a variable 
declaration by the same name?

For example, gcc 1.37.1 using -ansi -pedantic -W behaves as indicated on 
the following source (the numbers 0-2 are for reference later):

typedef int thing;

void f ()
{
  thing t1;          /** (0) **/

  t1 = 1;

  {
    int thing;       /** (1) compiler not confused yet **/

    thing = 0;
    h(thing);
  }

  {
    thing t2;
    int   thing;
    thing t3;        /** (2) breaks **/

    thing = 0;

    {
      thing t4;

      g(t1,t2,t3,t4,thing);
    }
  }
}

What does the standard have to say about all this ? Is the decl at (1)
legal ? should (2) be legal and gcc fails to conform ? 


What about C++ ? same/different rules about this issue ?


Thanx !

Rob Shaw, rjshaw at ocfmail.ocf.llnl.gov, (415) 423-3916 


===============================================================================
 Rob Shaw                                              rjshaw at ocfmail.llnl.gov
===============================================================================



More information about the Comp.lang.c mailing list