| delorie.com/archives/browse.cgi | search |
| From: | "John M. Aldrich" <fighteer AT cs DOT com> |
| Newsgroups: | comp.lang.c,comp.os.msdos.djgpp |
| Subject: | Re: Casting void pointers |
| Date: | Mon, 22 Jun 1998 23:55:38 -0400 |
| Organization: | Two pounds of chaos and a pinch of salt. |
| Lines: | 25 |
| Message-ID: | <358F273A.8845B85F@cs.com> |
| References: | <6mkaos$k7o AT dfw-ixnews6 DOT ix DOT netcom DOT com> <358DC1FA DOT 443E297D AT cs DOT com> <898511636snz AT genesis DOT demon DOT co DOT uk> |
| NNTP-Posting-Host: | ppp148.cs.net |
| Mime-Version: | 1.0 |
| To: | djgpp AT delorie DOT com |
| DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
> >int main( void )
> >{
> > void *vp = foo;
>
> Your compiler should have generated a diagnostic for this. The C language
> requires a cast to convert between void * and function pointers (in both
> directions). Note that C doesn't guarantee that a void * object can properly
> hold a funciton pointer. You should avoid doing this.
gcc with '-Wall' didn't say anything about that code. However, I just
tested it with '-ansi' and got the following warning:
void.c: In function `main':
void.c:10: warning: ANSI forbids initialization between function pointer
and `void *'
So you're right. Thanks for pointing out the mistake.
--
---------------------------------------------------------------------
| John M. Aldrich, aka Fighteer I | mailto:fighteer AT cs DOT com |
| "Starting flamewars since 1993" | http://www.cs.com/fighteer/ |
| *** NOTICE *** This .signature | ICQ UIN#: 7406319 |
| is generated randomly. If you don't like it, sue my computer. |
---------------------------------------------------------------------
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |