C strongly typed?

Richard O'keefe ok at goanna.oz.au
Thu Mar 8 10:11:17 AEST 1990


In article <849 at enea.se>, sommar at enea.se (Erland Sommarskog) writes:
> C strongly typed?  If I write something like: (I don't speak C
> so the syntax is probably bogus.)

>     typedef apple int;
>     typedef orange int;
>     apple a;
>     orange b;
>     ...
>     a = b;

> Will a "modern" compiler object?

No, of course not.  Try it in Pascal:
	program main;
	type
	    apple  = integer;
	    orange = integer;
	var
	    a: apple;
	    o: orange;
	begin
	    a := o;
	end.
A Pascal compiler may complain that "o" is uninitialised, but it
*must* accept the assignment as well-typed.  (I tried it.)

Try it in Ada (not checked, as I haven't access to an Ada compiler):
	declare
	    subtype apple  is integer;
	    subtype orange is integer;
	    a: apple;
	    o: orange := 1;
	begin
	    a := o;
	end
Again, the assignment is well-typed.  Why should C be different?



More information about the Comp.lang.c mailing list