Sunday, August 28, 2011

Comparing Function Pointers







#include
//define the calling convention
int __cdecl Dolt(float a,char b,char c); //Borland & Microsoft
//void Dolt(float a,char b,char c) __attribute__((cdecl)); //GNU GCC
int main(){
	int (*pt2Function)(float,char,char)=NULL;
	int a;
	//assignment an address to function pointer
	pt2Function=&Dolt;	
	//comparing function pointer
	if(pt2Function>0){
		if(pt2Function==&Dolt){
			printf("Pointer points to Dolt\n");
			//calling a function using function Pointer
			//int result=pt2Function(12,'a','b'); //c short way
			int result=(*pt2Function)(12,'a','b');//c
			printf("%d\n",result);
		}
		else
			printf("Pointer does not points to Dolt\n");
	}
	else
		printf("Pointer not initialized!!\n");
	getchar();getchar();
	return 0;
}
int Dolt(float a,char b,char c){printf("Dolt\n");return int(a+b+c); }

No comments:

Post a Comment