home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!crdgw1!rdsunx.crd.ge.com!bart!volpe
- From: volpe@bart.NoSubdomain.NoDomain (Christopher R Volpe)
- Newsgroups: comp.lang.c
- Subject: Re: Is that ansi ?
- Message-ID: <1993Jan8.191358.25333@crd.ge.com>
- Date: 8 Jan 93 19:13:58 GMT
- References: <1992Dec30.203127.25625@jpradley.jpr.com> <725809262snz@rcsl.demon.co.uk> <1993Jan8.142730.20697@osf.org> <mcdonald.28@aries.scs.uiuc.edu>
- Sender: volpe@bart (Christopher R Volpe)
- Reply-To: volpe@ausable.crd.ge.com
- Organization: GE Corporate Research & Development
- Lines: 54
- Nntp-Posting-Host: bart.crd.ge.com
-
- In article <mcdonald.28@aries.scs.uiuc.edu>, mcdonald@aries.scs.uiuc.edu (J. D. McDonald) writes:
- |> In article <1993Jan8.142730.20697@osf.org> daniel@moonshine.osf.org (Daniel Dardailler) writes:
- |>
- |> >A compiler is reporting the following warning:
- |>
- |> > "void * and function pointers are not convertible to each other"
- |>
- |> >when encountering:
- |>
- |> > void * p = (void *) func ; /* func of any kind */
- |>
- |>
- |> I'm afraid it's true, and one of the most serious faults of ANSI C.
- ^^^^^^
-
- You mean "faults of C". This is not new to ANSI C.
-
- |>
- |> Function pointers are orthogonal to everything else. What you can do
- |> is somehow convert them to an integer type and convert that to
- |> void * pointer and then go back. The standard itself does not
- |> guarantee that the conversion will get back the right answer however.
-
- Huh? Function pointers can no more be converted to integers than they can
- be converted into object pointers. There is nothing that says a
- function pointer will even *fit* in an integer or an object pointer.
-
- |> (For those who need a proof, checked with Doug Gwyn, that this can be done:
- |> enclose the function pointer in a struct, write out the struct to a
- |> file using fwrite, then read back in into a char array of the correct size.
- |> This is guaranteed to work.)
-
- And how is this useful?
-
- |> Another way is to try and use unions. This
- |> is not absolutely guaranteed to work.
-
- What are you suggesting he do with the union?
-
- |>
- |> Doug McDonald
-
- Daniel-
- Just change the declaration to the following:
-
- void (*p)() = (void (*)()) func; /* func of any kind */
-
- -Chris
-
- --
- ==================
- Chris Volpe
- G.E. Corporate R&D
- volpecr@crd.ge.com
-