typedef laxity

Michael J. Young mjy at sdti.UUCP
Tue Apr 19 00:04:00 AEST 1988


In article <4399 at ihlpf.ATT.COM> nevin1 at ihlpf.UUCP (00704a-Liber,N.J.) writes:
>Here is one that I see a lot among beginning C programmers:
>
>	typedef	char *	string;
>
>If I have the following declaration:
>
>	string	foo;
>
>I really don't want
>
>	foo = "bar";
>
>to be an error or even a warning from lint.

Actually, this probably isn't a good example.  A more likely implementation
of strong typing of typedefs would treat the base type as compatible with
a new type derived from it.  For example, in Modula-2 (taken directly from
Wirth's book):
	TYPE A = ARRAY [0..99] OF CHAR;
	     B = ARRAY [0..99] OF CHAR;
	     C = A;
Variables of type C are compatible with those of type A, but A and B are
incompatible.  Similarly, variables of type A are compatible with those of
type ARRAY [0..99] of CHAR.

Using this model, type string should be compatible with string literals, which
in this context are just char *.
-- 
Mike Young - Software Development Technologies, Inc., Sudbury MA 01776
UUCP     : {decvax,harvard,linus,mit-eddie}!necntc!necis!mrst!sdti!mjy
Internet : mjy%sdti.uucp at harvard.harvard.edu      Tel: +1 617 443 5779
"Bill & Opus in '88" -- Consider the alternatives!



More information about the Comp.lang.c mailing list