advice statement

jrv at mitre-bedford.ARPA jrv at mitre-bedford.ARPA
Mon Aug 27 08:55:00 AEST 1984


I'd like to see a statement added to C to let the programmer
declare the fraction of the time he expects an expression to be
nonzero (true). A typical use might be:
 
	root=x/2; next_root=x;
	while(root!=next_root \.90)
		{root=next_root;
		next_root=(root+x/root)/2.;
		}
 
...where the programmer expects the completion test to fail
90% of the time. (By the way, I have no particular love for
this syntax.)
 
This feature would have the following uses:
 
(1)	The COMPILER, when trying to optimize loops, normally
tries to take expensive operations out of a loop and move them
before or after the loop ("strength reduction"). If the loop
is hardly ever executed, this is a bad idea. The programmer
ought to be able to advise the compiler of this situation.
 
(2)	The PROGRAM TESTER (whether human or software) could
check the correctness of the programmer's guess and warn him
if it were out of line. The particular value 1 (always true)
could signal an invariant for which a proof might be attempted.

(3)	A READER of the program, on the first pass, could
follow only the "most of the time" paths, thereby getting an
overview of the program without getting confused by such
things as error handling and garbage collecting.
 
Does anybody else think this is a good idea?
			- Jim Van Zandt



More information about the Comp.lang.c mailing list