Path: utzoo!mnetor!uunet!husc6!bloom-beacon!mit-eddie!uw-beaver!apollo!mrst!sdti!mjy From: mjy@sdti.UUCP (Michael J. Young) Newsgroups: comp.lang.c Subject: Re: typedef laxity Message-ID: <251@sdti.UUCP> Date: 18 Apr 88 14:04:00 GMT References: <1070@maynard.BSW.COM> <542@picuxa.UUCP> <1071@maynard.BSW.COM> <4399@ihlpf.ATT.COM> Reply-To: mjy@sdti.UUCP (0000-Michael J. Young) Organization: Software Development Technologies, Sudbury MA Lines: 33 In article <4399@ihlpf.ATT.COM> nevin1@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@harvard.harvard.edu Tel: +1 617 443 5779 "Bill & Opus in '88" -- Consider the alternatives!