Re: Java puzzler
On 5/12/2011 6:18 PM, Patricia Shanahan wrote:
and add rules for deciding when to do overflow detection.
What I envision is only to only add the deciding in the compiler, not at
run time.
I'm not talking about setting a mode per thread or application. I only
want to affect what byte codes get generated at compile time.
Everything already compiled or compiled with existing options retains
its current semantics.
For example, if I do something like this
public int encryptAndCount( byte[] buffer ) {
@strictint // assume this turns on overflow checking
int i = 0;
int count = 0;
while( buffer[i] != 0 ) { // assume null terminated
count++;
encrypt( buffer, i );
}
return count;
}
and encrypt is something like this:
public class Encrypt {
private static byte rand;
public static void encrypt( byte[] buffer, int i offset ) {
rand += 42; // world's worst encryption
buffer[offset] ^= rand;
}
}
the method encryptAndCount has overflow detection, but that does not
"flow into" the method encrypt. They are distinct compilation units,
and in this case I immagine that "@strictint" only applies to one method
at a time anyway. So it all depends on the byte codes, not threads or
program flow, and doesn't happen dynamically at run time.