[M3devel] introducing VAR in more places?

Rodney M. Bates rodney.bates at wichita.edu
Fri Feb 15 00:22:06 CET 2008


Detecting use of uninitialized variables statically is undecidable,
although a good many specific (and common) cases can be caught or
ruled out.

Detecting at runtime requires a spare bit pattern that normal values
of the type don't use, or an extra bit or something--not too convenient
for some types.

I have always been a bit ambivalent about Modula-3's rule that every
variable is initialized to some unspecified bit pattern that is a
valid value of the type.  I understand this is the minimum requirement
to ensure type safety.  But for the same price already paid to do this
(runtime initialization code), we could have default initialization to a
language-specified value, which would make for more consistent behavior.

I have been gradually expanding the habit of writing an explicit initial
value on just about everything, whether bug-free code would need it or not,
just for the reduced risk of unreproduceable bugs.

Of course, if the type's representation uses every bit pattern, then the
rule we have has no cost, whereas a language-specified initial value would.

Jay wrote:
...
> Java and I presume C# have a nice feature here too where they require 
> the compiler to error for use of uninitialized variables, though I 
> suspect the specced algorithm misses some things, like:
>  
>   if (...) 
>     initialize x 
>  
> common code 
>  
>   if (same thing) 
>     use x   <== possible use of uninitialize x, not
>  
> At least I've seen other tools (not Java/C# compilers, I don't use 
> those) get confused by this..
>-- 
-------------------------------------------------------------
Rodney M. Bates, retired assistant professor
Dept. of Computer Science, Wichita State University
Wichita, KS 67260-0083
316-978-3922
rodney.bates at wichita.edu



More information about the M3devel mailing list