Xref: utzoo comp.lang.c:35134 comp.std.c:4106 Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!think.com!samsung!spool2.mu.edu!uwm.edu!lll-winken!ames!amdahl!rtech!ingres!jab From: jab@ingres.com (jeff bowles) Newsgroups: comp.lang.c,comp.std.c Subject: Re: (void *) to function pointer Message-ID: <1991Jan10.204613.27415@ingres.Ingres.COM> Date: 10 Jan 91 20:46:13 GMT References: <1991Jan9.000809.9152@brolga.cc.uq.oz.au> Reply-To: jab@crane.Ingres.COM (jeff bowles) Organization: Ask Computer Systems Inc., Ingres Division, Alameda CA 94501 Lines: 35 In article <1991Jan9.000809.9152@brolga.cc.uq.oz.au> gottsc@citrus.citr.uq.oz.au (John Gottsc) writes: > >can anybody tell me what the ANSI C standards state regarding conversion >between a (void *) and a function pointer (i.e. is this type of >conversion possible in ANSI C)? > >We have a machine (a UNISYS 1100) on which this type of conversion >is impossible, and I have two documents >("Notes on Writing Portable Programs in C" by Dolenc et al, and >"Recommended C style and Coding Standards") which state that a (void *) >is only guaranteed to be large enough to hold a pointer to any *data* >object) and is not suitable for a generic function pointer. It was my impression that a "void *" had to be large enough to contain any other kind of pointer, and that there were no rules that said that you had to be able to dereference a "void *" without converting it to some other pointer type first. For example, say a "pointer-to-function" would need to contain a segment number in addition to the address of the first instruction of the function. An call through this sort of pointer might mean "pry the segment number out of the pointer, do three hand-stands to map in that segment, then pry the address of the first instruction of the function and do the special procedure call to jump to that routine." This might take 80-bits or 160-bits to store all the information to call a function indirectly, so that "sizeof" for a "pointer-to-function" is a pretty big number. Then "void *" would have to be at least that large. There is no guarantee that conversion to any other type of pointer and back again retains all information. (I heard that they put in a hack so this would be true for "char *" also, but "say it ain't so!") Jeff Bowles -- "A wise man turneth away politicians." (or something like that)