Language transitions

Allen cca at pur-phy.UUCP
Sat Feb 9 01:36:18 AEST 1985


>                                          ... With all his talk about
> the importance of data hiding and locality, he did not include local
> statics. To get a static variable it must be global! This is significant
> lack, I use local statics regularly for internal state variables, which
> is what they are for.  I also do not seem to remember any facility
> for type casting or its equivalent, very useful for general purpose
> routines and record type.

Let's make sure we get the definitions straight here.  For a variable to be
"static" it must be declared in a module (i.e. not a procedure).  Hence it
is "global" to the module.  It is NOT visible to the outside world unless it
is explicitly exported.  Declaring a variable in the implementation part of
a module is equivalent to declaring it to be a static variable in a C file.

If you want even more restriction on where it's visible, you can tuck it
away in a local module.

Type casting most definitely IS included.  Any variable may be cast to
another type OF THE SAME SIZE as follows:

	TYPE
	    aType1 : ... (* whatever *)
	    aType2 : ... (* whatever *)
	VAR
	    aVar1 : aType1 ;
	    aVar2 : aType2 ;
	BEGIN
	    ...
	    aVar2 := aType2(aVar1) ;
	    ...

For types not of the same size this doesn't work.  For enumerated types, the
portable thing to do is to use VAL and ORD (CHR for chars if you want).

Charlie Allen	cca at pur-phy



More information about the Comp.lang.c mailing list