C strongly typed?

Lars P. Fischer fischer at iesd.auc.dk
Wed Mar 14 07:26:05 AEST 1990


In article <862 at enea.se> sommar at enea.se (Erland Sommarskog) writes:
>Well, apparently I am allowed to mix apples and oranges. If I have
>two types of data that both happens to be represented by integers,
>but have no logical connection what so ever I cannot apparently 
>express that in C. 

True. C has type synonyms, but you cannot introduce new types. It a
pain at times, but you learn to live with it. Note that this does
*not* mean that C is not strongly typed (it is). It means that there
are some type constructions mechanisms that are not available in C.

>And consequently I cannot take help from the
>compiler to catch inadvertent mixups in for instance procedure calls.

However:

   banach> cat te.c
   typedef enum { o1, o2 } orange ;
   typedef enum { a1, a2 } apple ;

   orange o;
   apple a;

   void main ()
   {
	   o = o1;
	   a = o;
   }

   banach> lint te.c
   te.c(10): warning: enumeration type clash, operator =
   banach>

Use lint, not Ada.

/Lars
--
Lars Fischer,  fischer at iesd.auc.dk   | Q: How does a project get to be one
CS Dept., Univ. of Aalborg, DENMARK. | year late?  A: One day at a time.



More information about the Comp.lang.c mailing list