maart@cs.vu.nl (Maarten Litmaath) (08/18/89)
gwyn@smoke.BRL.MIL (Doug Gwyn) writes: \In article <13572@bloom-beacon.MIT.EDU> scs@adam.pika.mit.edu (Steve Summit) writes: \... \> #ifndef _VA_LIST \> #define _VA_LIST \> typedef int *__va_list; \> #endif \... \since size_t is a typedef it must be protected by some sort of \one-time interlock. The pANS allows a preprocessor redefinition equal to the original definition: #define pipo aap #define pipo aap #define clown(x, y) monkey(y, x) #define clown(a, b) monkey(b, a) /* allowed? */ Why is a type-redef still forbidden? typedef foo bar; typedef foo bar; -- kilogram, n.: the amount of cocaine |Maarten Litmaath @ VU Amsterdam: you can buy for $100K. |maart@cs.vu.nl, mcvax!botter!maart
gwyn@smoke.BRL.MIL (Doug Gwyn) (08/19/89)
In article <3020@solo1.cs.vu.nl> maart@cs.vu.nl (Maarten Litmaath) writes: >Why is a type-redef still forbidden? Because to do otherwise would result in severe parsing problems.
dfp@cbnewsl.ATT.COM (david.f.prosser) (08/19/89)
In article <3020@solo1.cs.vu.nl> maart@cs.vu.nl (Maarten Litmaath) writes: >The pANS allows a preprocessor redefinition equal to the original definition: > > #define pipo aap > #define pipo aap > #define clown(x, y) monkey(y, x) > #define clown(a, b) monkey(b, a) /* allowed? */ The parameter names must match as well, thus this example is not a valid (benign) redefinition, even though they are functionally equivalent. > >Why is a type-redef still forbidden? > > typedef foo bar; > typedef foo bar; Macro definitions are easy to distinguish from regular text. Testing for valid redefinition is (mostly) a simple text-based comparison. Typedef names are more difficult to manage. For example, given typedef int INT; then { typedef unsigned INT; is a declaration of a local typedef name representing "unsigned int". But if the first typedef was followed by { typedef const INT; then it is a "useless" declaration because const and volatile are allowed to modify a known typedef name. (Such a "useless" declaration is required to cause a diagnostic.) Many C compilers choose to recognize typedef names as special in the lexical analysis stage, primarily because the grammar makes a big distinction between regular and typedef names. Allowing benign redefinition of typedef names makes this tricky process even more complex. Nevertheless, I believe that they should have been allowed, but that's only my opinion. Dave Prosser ...not an official X3J11 answer...
diamond@csl.sony.co.jp (Norman Diamond) (08/22/89)
In article <3020@solo1.cs.vu.nl> maart@cs.vu.nl (Maarten Litmaath) writes: >>Why is a type-redef still forbidden? In article <10784@smoke.BRL.MIL> gwyn@brl.arpa (Doug Gwyn) writes: >Because to do otherwise would result in severe parsing problems. It is very believable that the parsing problems are severe. However, I believe that every C compiler already solves those parsing problems. typedef int *(*my_type)(); /* my global type */ void my_func() { typedef char ***my_type[5]; /* my local type */ (It would also be legal if my local type shadowed my global type instead of being different.) So parsers already have to be prepared for possible-typedef identifiers. -- -- Norman Diamond, Sony Computer Science Lab (diamond%csl.sony.jp@relay.cs.net) The above opinions are inherited by your machine's init process (pid 1), after being disowned and orphaned. However, if you see this at Waterloo or Anterior, then their administrators must have approved of these opinions.