Feature for the next C version

William Davidsen davidsen at sungod.crd.ge.com
Sat Jul 29 04:58:14 AEST 1989


In article <18764 at mimsy.UUCP> chris at mimsy.UUCP (Chris Torek) writes:

| Having a complete binary tree (which is a condition for heaps) means
| shorter code paths.  A plain binary tree will work, but if it is
| unbalanced you will end up doing more comparisons than necessary.
| (`Complete' means that if you number the nodes like this:
| 
| 			1
| 		2		3
| 	     4     5	     6     7
| 	    8 9  10 11     12 13 14 15

  This brings up the one feature of FORTRAN which is missing and would
be useful in C (and other structured languages)... the arithmetic IF.

  When doing tree searches and many kinds of sorts, you often have logic
which looks something like this:
	if (a == b) {
		/* match found */
	}
	else if (a < b) {
		/* search lower portion of the tree */
	}
	else {
		/* search upper portion of the tree */
	}

  While most compilers will get rid of common subexpressions and stuff
in this case, the code generated rarely makes use of the repeated
testing of flags set by one compare, and the code is not as readable as
it might be. Some contruct which clearly shows what the user is trying
to do would add to the readability, if not the speed, of the code.
	bill davidsen		(davidsen at crdos1.crd.GE.COM)
  {uunet | philabs}!crdgw1!crdos1!davidsen
"Stupidity, like virtue, is its own reward" -me



More information about the Comp.lang.c mailing list