#include<stdio.h>
struct file{
int a;
开发者_开发知识库 int b;
int (*fp) (int ,int);
};
static int sum(int a, int b)
{
return(a+b);
}
void main()
{
struct file var;
int sum1=0;
var.fp=∑
sum1=fp(2,4);
printf("\nsum is %d ",sum1);
}
how to call the function..?? i am getting an error called as undefined reference to fp..???
Since its a member of the structure you have to qualify it:
sum1 = var.fp( 2, 4 );
You meant to say sum1 = var.fp(...)
or sum1 = (*var.fp)(...)
but you typed fp(...)
. C implicitly defined an external fp() for you to call. The compiler has to do this in order to compile legacy C code.
Use cc -Wall ...
to generate errors for missing forward declarations.
Have you tried changing:
sum1=fp(2,4);
To:
sum1=var.fp(2,4);
?
精彩评论