"Numerical Recipes in C" is nonportable code

M.T.Russell mtr at eagle.ukc.ac.uk
Thu Sep 15 22:40:58 AEST 1988


In article <8470 at smoke.ARPA> gwyn at brl.arpa (Doug Gwyn (VLD/VMB) <gwyn>) writes:
>In article <1429 at ficc.uu.net> peter at ficc.uu.net (Peter da Silva) writes:
>>What's to stop you from doing the following:
>>	Generate code in an array.
>>	Jump to the beginning of the array. *
>>... I can't see how you could write a valid 'C' compiler that wouldn't
>>let you violate this protection.
>
>That's simple.  All the compiler has to do is detect any attempt to
>use a data object as a function.  The only way to even attempt this in
>standard C is via an explicit cast to a function pointer somewhere,
>which is where the compiler would enforce the constraint.

There is another way to treat a data object as a function:

	union foo {
		char *data;
		int (*func)();
	};

The compiler would either have to prohibit unions with both text and
data pointers or do runtime bookkeeping to remember what was last
stored in such unions.

Mark Russell
mtr at ukc.ac.uk



More information about the Comp.lang.c mailing list