C strongly typed?

Richard O'keefe ok at goanna.oz.au
Fri Mar 9 10:09:58 AEST 1990


Concerning whether C is strongly typed; I gave Pascal and Ada equivalents
of the fragment which was alleged to show C not to be strongly typed.
In article <1990Mar8.142433.13559 at ncsuvx.ncsu.edu>, jwb at cepmax.ncsu.EDU (John W. Baugh Jr.) writes:
> I think the issue here is "type equivalence,"  ...
> ... ISO/ANSI Pascal standard defines equivalence based on name.
> 
>   type
>     t1 = array[1..3] of boolean;
>     t2 = array[1..3] of boolean;
>   var
>     v1 : t1;
>     v2 : t2;
>    
> the types of v1 and v2 are distinct under name equivalence, but equal
> under structural equivalence.

Quite right.  But it isn't relevant to the example under discussion.
Remember, the C fragment was
	typedef int apple, orange; apple a; orange b; a = b;
The Pascal equivalent of such a typedef is
	type <id> = <type id>;
and that does NOT introduce a new name.  For example,
    type
	t1 = array[1..3] of boolean;
	t2 = t1;	(* NO NEW TYPE IS INTRODUCED HERE *)
    var
	v1: t1;
	v2: t2;
    begin
	v2 := v1;
is perfectly legal Pascal.  Someone else claimed that the fact that
	char c; int i; i = c;
or something like that is legal C also shows that C is not strongly
typed.  Again, Pascal and Ada are exactly the same.  The Pascal
equivalent of C's "char" is
	const minChar = {-128, or 0, or what have you};
	      maxChar = {127, or 255, or what have you};
	type cChar = minChar..maxChar;
The fact that
	var c: cChar; i: integer; begin i := c;
is legal is not normally held to show that Pascal is not strongly
typed; why should the same fact be held against C?  True, C has no
equivalent of Pascal's character type, but the absence of an equivalent
for some other language's data type is not fatal to being strongly typed.



More information about the Comp.lang.c mailing list