typedef laxity

Peter J Desnoyers peter at athena.mit.edu
Fri Apr 15 08:43:13 AEST 1988


> (not sure who wrote this...)
>> 	typedef int TEMPERATURE;
>> 	typedef int PRESSURE;
>> 	TEMPERATURE tx, ty;
>> 	PRESSURE px, py;
>> 	ty = py;		/* type clash */
>> I _know_ how it works.  I am arguing that how it works is a _bad thing_.
>
My opinion of this is the following:

(1) I like strong typechecking. For true typechecking, typedef must
create a NEW type, rather than a synonym for an existing type.

(2) The language features necessary to do such typechecking are not
present in C. You can't require values in an expression to be of the
same type when they must be promoted to a possibly different type
before the expression is evaluated. You really need something
equivalent to overloading and inheritance to be able to do such
typechecking rationally.

Unless you turn C into a COMPLETELY different language (don't laugh -
they may do that to FORTRAN) I think we're stuck with typedef creating
an alias.

				Peter Desnoyers
				peter at athena.mit.edu



More information about the Comp.lang.c mailing list