Hashing to generate unique 6-char names

Kevin Martin kpmartin at watmath.UUCP
Sat Oct 20 06:34:51 AEST 1984


Unfortunately, I lost the original article. It was about 80 to 100 lines
extolling the virtues of hashing to generate a six-character identifier
from a longer one.

The article claims that the only way one can get undetected clashes is
through an incorrect program (two clashing references, but only one of the
variables actually defined). Unfortunately, correct programs can also
get undetected errors. Assume the names 'x' and 'y' happen to hash the same.
In file extern.c:
	int x = 5;
	int y = 10;

Since the two variables clash, 'y' gets re-hashed. Now, in foo.c:
	foo() {
		x = 10;
	}

and in bar.c:
	bar() {
		y = 10;
	}

Surprise! Both foo and bar assign 10 to 'x', leaving 'y' untouched.


Although hashing appears to make all the characters significant, it
actually makes all the characters partially significant in a manner that
is impossible to describe to the user. At least truncating the name to six
characters (or whatever) is an easy concept to explain.
                   Kevin Martin, UofW Software Development Group



More information about the Comp.lang.c mailing list