| delorie.com/archives/browse.cgi | search | 
| From: | jvasquez AT getntds DOT spam DOT com (John Vasquez) | 
| Newsgroups: | comp.os.msdos.djgpp | 
| Subject: | pointer to functions - Warning error | 
| Date: | Mon, 18 Dec 2000 18:55:56 GMT | 
| Organization: | CTSnet Internet Services | 
| Lines: | 40 | 
| Message-ID: | <3a3e5883.8164479@news.connectnet.com> | 
| X-Trace: | thoth.cts.com 977165751 34789 207.110.36.153 (18 Dec 2000 18:55:51 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 | 
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
| webmaster | delorie software privacy | 
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |