Topic: Is this legal? I think not.


Author: fjh@mundook.cs.mu.OZ.AU (Fergus Henderson)
Date: 1997/11/01
Raw View
mlg@scr.siemens.com (Michael Greenberg) writes:

>Is the following legal? [...]
>
>  typedef struct { } foo;
>  struct foo bar;

No.

 |   9.1  Class names                                          [class.name]
 [...]
 | 5 A typedef-name (_dcl.typedef_) that names a class is a class-name, but
 |   shall not be used in an elaborated-type-specifier; see also _dcl.type-
 |   def_.

 |   7.1.3  The typedef specifier                             [dcl.typedef]
 [...]
 | 4 A typedef-name that names a class is a class-name (_class.name_).  The
 |   typedef-name shall not be used after a class, struct, or union  prefix
 |   and not in the names for constructors and destructors within the class
 |   declaration itself.  [Example:
 |           struct S {
 |               S();
 |               ~S();
 |           };
 |
 |           typedef struct S T;
 |
 |           S a = T();      // ok
 |           struct T * p;   // error
 |    --end example]

--
Fergus Henderson <fjh@cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3         |     -- the last words of T. S. Garp.
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: mlg@scr.siemens.com (Michael Greenberg)
Date: 1997/11/01
Raw View
Is the following legal?  I am trying to port from one compiler to
another that contains the following:

  typedef struct { } foo;
  struct foo bar;

Thanks,





--
Michael Greenberg                      email: mgreenberg@scr.siemens.com
Siemens Corporate Research             phone: 609-734-3347
755 College Road East                  fax: 609-734-6565
Princeton, NJ 08540
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]