Path: utzoo!attcan!uunet!mcvax!ukc!eagle!mtr From: mtr@eagle.ukc.ac.uk (M.T.Russell) Newsgroups: comp.lang.c Subject: Re: "Numerical Recipes in C" is nonportable code Message-ID: <5514@eagle.ukc.ac.uk> Date: 15 Sep 88 12:40:58 GMT References: <664@lindy.Stanford.EDU> <6758@megaron.arizona.edu> <718@gtx.com> <640@drilex.UUCP> <1429@ficc.uu.net> <8470@smoke.ARPA> Reply-To: mtr@arthur.UUCP (M.T.Russell) Organization: Computing Lab, University of Kent at Canterbury, UK. Lines: 26 In article <8470@smoke.ARPA> gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) writes: >In article <1429@ficc.uu.net> peter@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@ukc.ac.uk