dglasser@yale.ARPA (Danny Glasser) (10/09/84)
Let's say I have the following C program:
/* Beginning */
typedef int FOO ;
typedef int BAR ;
#define XXX (FOO) 1
main()
{
BAR fff ;
fff = XXX ;
}
/* End */
When I run lint or cc on this program (on 4.1BSD or 4.2BSD), I
get no complaints about the fact that fff is a variable of type
BAR and it is being assigned a value of type FOO. Now I wouldn't
want the C compiler to crap out on this code (as Pascal probably
would with the equivalent program), but shouldn't the compiler
(or at least lint) complain about this?
-- Danny Glasser
{decvax,allegra,ima}!yale!dglasser
Glasser-Daniel@YALE.ARPA
[NOT dglasser@YALE.ARPA]
henry@utzoo.UUCP (Henry Spencer) (10/14/84)
> typedef int FOO ; > typedef int BAR ; > > #define XXX (FOO) 1 > > ... > > BAR fff ; > > fff = XXX ; > > When I run lint or cc on this program (on 4.1BSD or 4.2BSD), I > get no complaints about the fact that fff is a variable of type > BAR and it is being assigned a value of type FOO. ... If you look at the specs of typedef, it's explicitly defined to be purely an abbreviation mechanism, with no effect on type matching. So this is legal C. It *would* be nice if lint would complain... -- Henry Spencer @ U of Toronto Zoology {allegra,ihnp4,linus,decvax}!utzoo!henry
ken@turtlevax.UUCP (Ken Turkowski) (10/15/84)
> Let's say I have the following C program: > > typedef int FOO ; > typedef int BAR ; > #define XXX (FOO) 1 > main() { > BAR fff ; > fff = XXX ; > } > > When I run lint or cc on this program (on 4.1BSD or 4.2BSD), I > get no complaints about the fact that fff is a variable of type > BAR and it is being assigned a value of type FOO. Now I wouldn't > want the C compiler to crap out on this code (as Pascal probably > would with the equivalent program), but shouldn't the compiler > (or at least lint) complain about this? I agree that the compiler or lint should complain. Otherwise there's no advantage to using a typedef over a #define. -- Ken Turkowski @ CADLINC, Palo Alto, CA UUCP: {amd,decwrl,flairvax,nsc}!turtlevax!ken ARPA: turtlevax!ken@DECWRL.ARPA
jlk@eisx.UUCP (Joe Klein) (10/15/84)
(K&R), page 141 - "It must be emphasized that a typedef declaration does not create a new type in any sense; it merely adds a new name for some existing type".