Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ames!umd5!trantor.umd.edu!chris From: chris@trantor.umd.edu (Chris Torek) Newsgroups: comp.lang.c Subject: Re: Casting function ptrs Message-ID: <2763@umd5.umd.edu> Date: 22 May 88 21:02:48 GMT References: <281@marob.MASA.COM> <7330003@hpcllz2.HP.COM> Sender: news@umd5.umd.edu Reply-To: chris@trantor.umd.edu (Chris Torek) Organization: University of Maryland, College Park Lines: 23 In article <7330003@hpcllz2.HP.COM> walter@hpcllz2.HP.COM (Walter Murray) writes: >... but I think the following has the virtue of being strictly >conforming per the dpANS. ... > >struct funcs {char *name; void (*func)();}; >char *foo() {return "It worked!";}; >struct funcs f = {"foo",(void(*)())foo}; This is not strictly conforming, because the standard does not say whether objects of type `void (*)()' are in any way compatible with objects of type `char *(*)()'. (It says very little about pointers to functions, no matter what the return type of the function. It does not even say whether `void *' and `t (*)()' are compatible.) Since, however, `char *' and `void *' are `the same', using a base type of `void *(*)()' should work. Most likely, pointers to any function, no matter what the return type, will have the same format, but it would be nice to have some guarantees. -- In-Real-Life: Chris Torek, Univ of MD Computer Science, +1 301 454 7163 Domain: chris@mimsy.umd.edu Path: ...!uunet!mimsy!chris