Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83 based; site houxf.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxt!houxm!houxf!jph From: jph@houxf.UUCP (J.HARKINS) Newsgroups: net.lang.c Subject: Re: Arcane C hacks? Message-ID: <1067@houxf.UUCP> Date: Tue, 25-Feb-86 19:47:06 EST Article-I.D.: houxf.1067 Posted: Tue Feb 25 19:47:06 1986 Date-Received: Fri, 28-Feb-86 05:44:09 EST References: <184@bu-cs.UUCP>, <592@bentley.UUCP> Organization: AT&T Bell Labs, Holmdel NJ Lines: 46 > In articles <184@bu-cs.UUCP> bu-cs!bzs (Barry Shein) writes: > >declare a table something like: int (*funtable[MAXFNS])() ; > >and just malloc the storage for the generated code. ... It should be > >quite portable (code generator aside) and is legal C. > > Well, some compilers will dislike the attempt to cast a (char *) into > a (int (*)()) ; in fact I think some will call it an outright error Huh??? This line of code DOES NOT cast a char * into an int. It is declaring that funtable is an array of MAXFNS elements, each of which is a pointer to a function that returns a int value. > (not just a warning). But in any case it is _not_ portable to the 3b2, BOLDERDASH!!! I have programs that use pointers to functions, some that run on 3B2/5's. The construct is totally(no flames, please) portable. As a matter of fact I have used this type of construct to allow emulation of UN*X signal processing on a non UN*X operating system that only allowed one routine to be specified for all signals. > because all programs are pure -- you can't goto/call data space, nor > can you read from the instruction stream. Some sort of chastity belt > in the hardware, I think. Whazat?? MOST(not all) programs are pure in this environment, yes. But that has nothing to do with being able to use a pointer to a function. The code that is executed is actually in the shared text region; it is only the pointer to the function that is in the data area. ------- Disclaimer: I hereby disclaim all my debts. ------ Jack Harkins @ AT&T Bell Labs Princeton Information (201) 949-3618 (201) 561-3370 houxf!jph