C strongly typed?

News system news at ism780c.isc.com
Tue Mar 13 11:35:56 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. And consequently I cannot take help from the
>compiler to catch inadvertent mixups in for instance procedure calls.
>

I am unaware of any commonly available language that prevents this form of
mistake.  Look at the following:

  double distance;
  double time;
  double velocity;

  velocity = distance/time;  /* this makes sense */
  velocity = distance+time;  /*  I mixed 'apples' and 'oranges' and produced
				 a lemon :-) */

I did read a paper (sorry, I don't have the reference) describing a language
that allowed one to augment the the type declaration with a units declaration
so as to be able to catch errors of this form.

   Marv Rubinstein



More information about the Comp.lang.c mailing list