| www.delorie.com/archives/browse.cgi | search |
| From: | John Kugelman <kugelman AT mnsinc DOT com> |
| Newsgroups: | comp.lang.c,comp.os.msdos.djgpp |
| Subject: | Re: Casting void pointers |
| Date: | Mon, 22 Jun 1998 01:31:01 -0400 |
| Organization: | Verio Mid-Atlantic |
| Lines: | 26 |
| Message-ID: | <358DEC15.7441F34@mnsinc.com> |
| References: | <6mkaos$k7o AT dfw-ixnews6 DOT ix DOT netcom DOT com> <358DE928 DOT 2F8C4608 AT mnsinc DOT com> |
| NNTP-Posting-Host: | kugelman.mnsinc.com |
| Mime-Version: | 1.0 |
| To: | djgpp AT delorie DOT com |
| DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
I wrote:
>
> double foo (double d)
> { return d * 2.0; }
>
> int main (void)
> {
> /* Store function pointer in "generic" pointer. */
> void (*func) (void) = foo;
>
> /* Cast pointer back to original type before calling it. */
> printf ("%f\n", ((double (*) (double)) func) (5.0));
>
> return 0;
> }
Silly me, I went and ignored my compiler's warnings (I just can't
explain it). There should be an #include <stdio.h> at the top, and foo
should be cast to the appropriate type in the initialization of func.
--
John Kugelman. kugelman AT mnsinc DOT com
I believe we can change anything.
I believe in my dream.
- Joe Satriani
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |