Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!usc!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!haven!mimsy!chris From: chris@mimsy.umd.edu (Chris Torek) Newsgroups: comp.lang.c Subject: Re: C strongly typed? Message-ID: <23014@mimsy.umd.edu> Date: 10 Mar 90 05:51:40 GMT References: <259@eiffel.UUCP> <1990Mar1.172526.28683@utzoo.uucp> <849@enea.se> <4440@ganymede.inmos.co.uk> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 47 In some article somewhere someone claims that because f() { typedef int apple, orange; apple a; orange o = 1; a = o; } compiles without complaint, C must therefore not be strongly typed. >In article <2963@goanna.oz.au> ok@goanna.oz.au (Richard O'keefe) points out that by this logic, neither is (part of) Ada: >> subtype apple is integer; >> subtype orange is integer; In article <4440@ganymede.inmos.co.uk> mph@lion.inmos.co.uk (Mike Harrison) says to use instead > type APPLE is new INTEGER; > type ORANGE is new INTEGER; Well, if we are allowed to rewrite the code arbitrarily, I suggest typedef struct { int value; } apple; typedef struct { int value; } orange; f(void) { apple a; orange o = { 1 }; /* NB: requires ANSI C */ a = o; } which is (surprise surprise) illegal. Those who will argue with Henry Spencer should read his original article (and perhaps his followup; I cannot recall whether there was one) closely: it says (paraphrased) a) typedef does not define a new type. b) `struct' defines a new type. c) If you want the compiler to complain, you must therefore not rely on `typedef' alone. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@cs.umd.edu Path: uunet!mimsy!chris