delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/12/18/14:42:06

From: jvasquez AT getntds DOT spam DOT com (John Vasquez)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: pointer to functions - Warning error
Date: Mon, 18 Dec 2000 19:20:08 GMT
Organization: CTSnet Internet Services
Lines: 61
Message-ID: <3a3e6258.10681619@news.connectnet.com>
References: <3a3e5883 DOT 8164479 AT news DOT connectnet DOT com>
X-Trace: thoth.cts.com 977167204 36559 207.110.36.153 (18 Dec 2000 19:20:04 GMT)
X-Complaints-To: abuse AT cts DOT com
X-Newsreader: Forte Free Agent 1.21/32.243
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Found the fix. 
If I do the following in the structure, The error disappeared.

int Myfunct(int x, void *adr);
typedef struct _MyStruct{
	int (*funct)();	//don't include the parameter list
}MyStruct;

in the code I do this:
int x;
void *adr;
MyStruct DefineStruct;	//define the structure
DefineStruct.funct = MyFunct; //set the pointer to function 
DefineStruct.funct(x, addr);	//call the function



On Mon, 18 Dec 2000 18:55:56 GMT, jvasquez AT getntds DOT spam DOT com (John
Vasquez) wrote:

>I have the latest DJGPP compiler.
>
>I use a lot of pointer to functions - If I define it this way I get no
>compiler warning (assignment from incompatible pointer type)
>int Myfunct(void);
>typedef struct _MyStruct{
>	int (*funct)(void);
>}MyStruct;
>
>in the code I do this:
>MyStruct DefineStruct;	//define the structure
>DefineStruct.funct = MyFunct; //set the pointer to function
>DefineStruct.funct();	//call the function
>}
>
>When I have a function that I pass parameters: like this
>int Myfunct(int x, void *adr);
>
>typedef struct _MyStruct{
>	int (*funct)(int x, void *adr);
>}MyStruct;
>
>in the code I do this:
>int x;
>void *adr;
>MyStruct DefineStruct;	//define the structure
>DefineStruct.funct = MyFunct; //set the pointer to function <---
>Generates a compiler warning message
>DefineStruct.funct(x, addr);	//call the function
>}
>I get the following compiler warning error at DefineStruct.funct =
>MyFunct; 
>
>Why? The code I am using was ported over from MS C compiler version
>6.0. and I am modifying the code for 32 bit operations. The MS C
>compiler never generated a warning error and the program works
>perfectly in DOS.
>
>Thank you
>John

- Raw text -


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