View previous topic :: View next topic |
Author |
Message |
pic user Guest
|
pointer to function |
Posted: Sat Jan 10, 2004 6:50 am |
|
|
what is the proper syntax for a pointer to a function
I have
long * func1;
func1=disp_character;
disp_character is defined
I get a compiler error 'improper use of a function identifier'
am using PCM version 3.169
thanks |
|
|
Ttelmah Guest
|
Re: pointer to function |
Posted: Sat Jan 10, 2004 6:55 am |
|
|
pic user wrote: | what is the proper syntax for a pointer to a function
I have
long * func1;
func1=disp_character;
disp_character is defined
I get a compiler error 'improper use of a function identifier'
am using PCM version 3.169
thanks |
The declaration here is saying that 'func1', is a pointer to a function returning a long. The defintion depends on what type the function returns.
Best Wishes |
|
|
pic_user Guest
|
|
Posted: Sat Jan 10, 2004 11:13 am |
|
|
still don't work.
a little more details
float c2f(float celsius);
float c2f(float clecius)
{
float f;
f=(celsius*1.8)+32;
return f;
}
main()
{
float c;
float * func1;
func1=c2f;
c=(func1) (32);
}
this is a sample of my code. Not sure whats wrong with it but it won't compile.
error : improper use of function identifier
any help would be greatly appreciated |
|
|
Ttelmah Guest
|
|
Posted: Sat Jan 10, 2004 4:27 pm |
|
|
pic_user wrote: | still don't work.
a little more details
float c2f(float celsius);
float c2f(float clecius)
//spelling error here
{
float f;
f=(celsius*1.8)+32;
return f;
}
main()
{
float c;
float * func1;
//declare as:
// float (*func1)(float);
//This says that func1, is a pointer to a function that requires a float
//argument, and returns a float. All parts of this are required.
func1=c2f;
c=(func1) (32);
//Here you need to use the function, not the pointer, so the declaration
//is:
// c=(*func1)(32);
}
this is a sample of my code. Not sure whats wrong with it but it won't compile.
error : improper use of function identifier
any help would be greatly appreciated |
This is standard C pointer handling, not a compiler problem. I suggest you read up, on how to use pointers to functions. :-)
Best Wishes |
|
|
pic_user Guest
|
|
Posted: Sat Jan 10, 2004 4:43 pm |
|
|
thanks. fixed it |
|
|
|