www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/04/07/00:57:59

Date: Sun, 7 Apr 1996 08:45:45 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Jethro Wright <Jetman AT gnn DOT com>
Cc: djgpp AT delorie DOT com
Subject: Re: A Proper Cast for a Funtion Ptr....
In-Reply-To: <199604051627.LAA11738@mail-e2b-service.gnn.com>
Message-Id: <Pine.SUN.3.91.960407083842.22284H-100000@is>
Mime-Version: 1.0

On Fri, 5 Apr 1996, Jethro Wright wrote:

> 	-  this is the prototype for the fn I want to pass:
> 
> 	void newfn( u_int s, void *, void * )
> 
> 	-  this is the prototype for the fn I'm supposed to use:
> 
> 	void oldfn( int s, void *, void * )
> 
> 	-  I "thought" a cast like this would work:
> 
> 	((void) ((int), (void *), (void *))) newfn

This should do the trick:

	(void (*)(int, void *, void *))newfn

But beware: when a C compiler sees this, it actually generates code to
call `newfn' with a calling sequence that is appropriate for `oldfn'.  In
this case, it converts `s' from int to unsigned int, but other subtle
things might be going on there too.  This is what casting function
pointers means.  It's best to avoid it, unless you can't do otherwise. 

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019