C strongly typed?
Chris Torek
chris at mimsy.umd.edu
Sat Mar 10 15:51:40 AEST 1990
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 at goanna.oz.au> ok at 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 at ganymede.inmos.co.uk> mph at 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 at cs.umd.edu Path: uunet!mimsy!chris
More information about the Comp.lang.c
mailing list