Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!henry From: henry@utzoo.UUCP (Henry Spencer) Newsgroups: net.lang.c Subject: Re: Ptr to func doesn't like casting?? Message-ID: <4688@utzoo.UUCP> Date: Tue, 27-Nov-84 12:24:47 EST Article-I.D.: utzoo.4688 Posted: Tue Nov 27 12:24:47 1984 Date-Received: Tue, 27-Nov-84 12:24:47 EST References: <13900010@acf4.UUCP> Organization: U of Toronto Zoology Lines: 27 > [Trying to store a char pointer in a function pointer is hard to get > past the compiler/lint] > > (char *)varname = function(); > doesn't work (lvalue required). > > And, > varname = (*function())(); > doesn't work consistantly. Well, you might try: varname = (int(*)())function(); which is the correct cast form -- get the value from the function and then cast it to pointer-to-int-function. However, I am morally bound to tell you that you are sinning :-), and in a somewhat unportable way. Pointers to functions and pointers to data are very different animals, and on some machines they are of different sizes. Using one to hold the other is hazardous. I believe the ANSI C draft outlaws such conversions altogether, although I haven't got my copy handy to check. Use a union; it's much more portable, and should shut the compilers up as a useful bonus. -- Henry Spencer @ U of Toronto Zoology {allegra,ihnp4,linus,decvax}!utzoo!henry