magic numbers

LaidigTL tll at druxu.UUCP
Tue Mar 6 14:48:26 AEST 1984


One little annoyance that appears with using "#!" as a magic number is
the old byte-ordering problem.  The magic number for an executable file
is defined to be a short int (maybe unsigned, I forget), so that the old
octal 407 is ^G^A on a PDP-11 or a VAX, but is ^A^G on some other
machines.  Similarly, depending on your machine, #! can have either of
two values.  You can get around this in several (semi-) portable ways, for
instance:

	1)  Have the kernel do a strncmp to test against #!, and integer
	tests for the magic numbers of binary executable files.  This is
	less efficient than is nice.

	2)  Test for the #! with an integer test for equality with '#!'
	if you believe in the portability of this.


			Tom Laidig
			AT&T Information Systems Laboratories, Denver
			...!ihnp4!druxu!tll



More information about the Comp.unix.wizards mailing list