typedef laxity

Michael Meissner meissner at xyzzy.UUCP
Fri Apr 8 03:22:57 AEST 1988


In article <1070 at maynard.BSW.COM> campbell at maynard.BSW.COM (Larry Campbell) writes:
| It seems to me someone should complain about this code:
| 
| 	typedef int TEMPERATURE;
| 	typedef int PRESSURE;
| 
| 	TEMPERATURE tx, ty;
| 	PRESSURE px, py;
| 
| 	ty = py;		/* type clash */
| 
| But none of the compilers I've tested (pcc, VAX-11 C, Wang VS C, Turbo C)
| complain about it, and, even worse, _lint_ doesn't complain!
| 
| Does anyone know of a lint or compiler that will complain about it?
| Does anyone disagree that lint's silence in this case is a bug?
| (Especially since lint does complain about mixing enum types...)

Actually if they complain about it, they are not following either K&R or
the ANSI draft, which quite clearly says that typedefs do NOT create a new
type, rather all it does is create a synonym for an existing type.  I've
heard that the Microsoft 4.00 (and presumably 5.00) C does this with a
compiler option.  Another way to get the protection is to use C++ and
declare the types to be a class (instead of a typedef).
-- 
Michael Meissner, Data General.		Uucp: ...!mcnc!rti!xyzzy!meissner
					Arpa/Csnet:  meissner at dg-rtp.DG.COM



More information about the Comp.lang.c mailing list