Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!seismo!umcp-cs!chris From: chris@umcp-cs.UUCP (Chris Torek) Newsgroups: net.lang.c Subject: Re: Arcane C hacks? Message-ID: <3374@umcp-cs.UUCP> Date: Wed, 26-Feb-86 20:40:47 EST Article-I.D.: umcp-cs.3374 Posted: Wed Feb 26 20:40:47 1986 Date-Received: Sat, 1-Mar-86 01:25:02 EST References: <184@bu-cs.UUCP>, <592@bentley.UUCP> <1067@houxf.UUCP> Organization: U of Maryland, Computer Science Dept., College Park, MD Lines: 49 In article <1067@houxf.UUCP> jph@houxf.UUCP (Jack Harkins) . . . responds to the following from Barry Shein: >>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 Jack Harkins says: >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. You are both right. It is obvious that the line Jack refers to is: int (*funtable[MAXFNS])(); while the code Barry refers to is: char *malloc(); funtable[n] = (int (*)()) malloc(codesize); (which does not appear in the quoted text, but is implied nonetheless.) So when Barry says: > it is _not_ portable to the 3b2, he is correct: you cannot invoke the allocated function without turning it into `code' first, for the hardware will not execute `data'; and when Jack says: >I have programs that use pointers to functions, some that run on 3B2/5's. >The construct is totally(no flames, please) portable. he is also correct: pointers to functions are portable. It is this specific usage---allocate data, fill with code, call data area as function---that is not. Hoping this will forestall further confusion, -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1415) UUCP: seismo!umcp-cs!chris CSNet: chris@umcp-cs ARPA: chris@mimsy.umd.edu