Problem assigning function to function pointer 
Author Message
 Problem assigning function to function pointer

I'm having problems with the below code....
    FuncPtr ptr; /*FuncPtr is my typedef'd pointer to a function*/
    ptr= sin; /*I thought that this would make the ptr point to the
function in math.h*/

I get the following error when trying to compile this-
/tmp/cca112771.o: In function `main':
/tmp/cca112771.o(.text+0xcc9): undefined reference to `sin'

I have math.h #include 'd in my code.
I've tried *ptr=sin, but that doesn't work, it gives me an invalid lvalue in
assignment error.
I've also tried doing cc prints.c -lm, which unfortunately did not
work.

Any ideas?
Thanks.



Fri, 08 Mar 2002 03:00:00 GMT  
 Problem assigning function to function pointer

Quote:
> Any ideas?

Yes. Post your code. What form does your declaration for FuncPtr take?

Is it:

typedef double (*FuncPtr) (double);

If it is, it should work (I tested it). It should accept sin as an argument,
assuming you really have "#include <math.h>" in your code.

--

Paul Lutus
www.arachnoid.com


Quote:
> I'm having problems with the below code....
>     FuncPtr ptr; /*FuncPtr is my typedef'd pointer to a function*/
>     ptr= sin; /*I thought that this would make the ptr point to the
> function in math.h*/

> I get the following error when trying to compile this-
> /tmp/cca112771.o: In function `main':
> /tmp/cca112771.o(.text+0xcc9): undefined reference to `sin'

> I have math.h #include 'd in my code.
> I've tried *ptr=sin, but that doesn't work, it gives me an invalid lvalue
in
> assignment error.
> I've also tried doing cc prints.c -lm, which unfortunately did not
> work.

> Any ideas?
> Thanks.



Fri, 08 Mar 2002 03:00:00 GMT  
 Problem assigning function to function pointer
That is exactly my definition- I'm including math.h and it still does not
work.
This is blowing my mind.


Quote:
> > Any ideas?

> Yes. Post your code. What form does your declaration for FuncPtr take?

> Is it:

> typedef double (*FuncPtr) (double);

> If it is, it should work (I tested it). It should accept sin as an
argument,
> assuming you really have "#include <math.h>" in your code.

> --

> Paul Lutus
> www.arachnoid.com



> > I'm having problems with the below code....
> >     FuncPtr ptr; /*FuncPtr is my typedef'd pointer to a function*/
> >     ptr= sin; /*I thought that this would make the ptr point to the
> > function in math.h*/

> > I get the following error when trying to compile this-
> > /tmp/cca112771.o: In function `main':
> > /tmp/cca112771.o(.text+0xcc9): undefined reference to `sin'

> > I have math.h #include 'd in my code.
> > I've tried *ptr=sin, but that doesn't work, it gives me an invalid
lvalue
> in
> > assignment error.
> > I've also tried doing cc prints.c -lm, which unfortunately did not
> > work.

> > Any ideas?
> > Thanks.



Fri, 08 Mar 2002 03:00:00 GMT  
 Problem assigning function to function pointer

Quote:

>That is exactly my definition- I'm including math.h and it still does not
>work.
>This is blowing my mind.

Take it in stages.  Write a small piece of code which invokes sin().
See if that compiles and links.  If it doesn't then your problem has
nothing to do with the pointer business.  If it does, try adding the
pointer stuff to the test program.  Does that work?  If so, remove
the invocation of sin() and try again.

Somewhere along the line you'll probably realise where it's going
wrong.

HTH
John
--
John Winters.  Wallingford, Oxon, England.

The Linux Emporium - a source for Linux CDs in the UK
See http://www.linuxemporium.co.uk/



Fri, 08 Mar 2002 03:00:00 GMT  
 Problem assigning function to function pointer
Ok- I tried your excellent suggestion.
Any reference to sin(x) gives me the same error as I got before.
I have #include <math.h> in the program.
I'm fairly confused.
Thanks


Quote:


> >That is exactly my definition- I'm including math.h and it still does not
> >work.
> >This is blowing my mind.

> Take it in stages.  Write a small piece of code which invokes sin().
> See if that compiles and links.  If it doesn't then your problem has
> nothing to do with the pointer business.  If it does, try adding the
> pointer stuff to the test program.  Does that work?  If so, remove
> the invocation of sin() and try again.

> Somewhere along the line you'll probably realise where it's going
> wrong.

> HTH
> John
> --
> John Winters.  Wallingford, Oxon, England.

> The Linux Emporium - a source for Linux CDs in the UK
> See http://www.linuxemporium.co.uk/



Fri, 08 Mar 2002 03:00:00 GMT  
 Problem assigning function to function pointer

Quote:

>Ok- I tried your excellent suggestion.
>Any reference to sin(x) gives me the same error as I got before.
>I have #include <math.h> in the program.

Now is the time to post your sample code and the exact command you use
to invoke your compiler. And consider (cross)posting to your compiler's
newsgroup.

Gergo

--
Then there was the Formosan bartender named Taiwan-On.

GU d- s:+ a--- C++>$ UL+++ P>++ L+++ E>++ W+ N++ o? K- w--- !O !M !V
PS+ PE+ Y+ PGP+ t* 5+ X- R>+ tv++ b+>+++ DI+ D+ G>++ e* h! !r !y+



Fri, 08 Mar 2002 03:00:00 GMT  
 Problem assigning function to function pointer
Thanks all,
I got the answer- I was incorrectly calling my compiler.
Thanks a lot,
Bill


Quote:
> I'm having problems with the below code....
>     FuncPtr ptr; /*FuncPtr is my typedef'd pointer to a function*/
>     ptr= sin; /*I thought that this would make the ptr point to the
> function in math.h*/

> I get the following error when trying to compile this-
> /tmp/cca112771.o: In function `main':
> /tmp/cca112771.o(.text+0xcc9): undefined reference to `sin'

> I have math.h #include 'd in my code.
> I've tried *ptr=sin, but that doesn't work, it gives me an invalid lvalue
in
> assignment error.
> I've also tried doing cc prints.c -lm, which unfortunately did not
> work.

> Any ideas?
> Thanks.



Fri, 08 Mar 2002 03:00:00 GMT  
 Problem assigning function to function pointer


Quote:


>> Ok- I tried your excellent suggestion.
>> Any reference to sin(x) gives me the same error as I got before.
>> I have #include <math.h> in the program.
>> I'm fairly confused.
>> Thanks
>If you are using some flavor of UNIX, Linux, or if you are using GCC, then:
>Add the command line flag -lm.

The command line that the original poster used already contained -lm (at
the end of the line too).

Quote:
>If you are using an older compiler, try adding something the compiler will
>recognize as floating point, like:
>double d = 1.5*3.;
>It's a FAQ.

But the OP already seems to have implemented the advice in the FAQ (or at
least as far as we can see without seeing the code).

--
-----------------------------------------


-----------------------------------------



Fri, 08 Mar 2002 03:00:00 GMT  
 Problem assigning function to function pointer
On Mon, 20 Sep 1999 17:25:24 -0700, "Bill Tice"

Quote:

>Thanks all,
>I got the answer- I was incorrectly calling my compiler.
>Thanks a lot,

Yes it's true you should always properly address your compiler. I call
mine Mr. gcc. I believe it finds anything else insulting. My computer
on the other hands responds better to pet names.
Regards,
Greg "the daemon made me do it" Martin


Sat, 09 Mar 2002 03:00:00 GMT  
 Problem assigning function to function pointer

Quote:

>I'm having problems with the below code....
>    FuncPtr ptr; /*FuncPtr is my typedef'd pointer to a function*/
>    ptr= sin; /*I thought that this would make the ptr point to the
>function in math.h*/

>I get the following error when trying to compile this-
>/tmp/cca112771.o: In function `main':
>/tmp/cca112771.o(.text+0xcc9): undefined reference to `sin'

>I have math.h #include 'd in my code.
>I've tried *ptr=sin, but that doesn't work, it gives me an invalid lvalue in
>assignment error.
>I've also tried doing cc prints.c -lm, which unfortunately did not
>work.

>Any ideas?
>Thanks.

including the header is not enough..
are you also linking in the lib?

perhaps.. -dlibmath

--
*/ unmatched closing comment



Sat, 09 Mar 2002 03:00:00 GMT  
 Problem assigning function to function pointer


<snip>

Quote:
> Greg "the daemon made me do it" Martin

Go stick it up your nose.

;-)

--
Richard Heathfield

"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.



Sat, 09 Mar 2002 03:00:00 GMT  
 Problem assigning function to function pointer

Quote:


>>I'm having problems with the below code....
>>    FuncPtr ptr; /*FuncPtr is my typedef'd pointer to a function*/
>>    ptr= sin; /*I thought that this would make the ptr point to the
>>function in math.h*/

>>I get the following error when trying to compile this-
>>/tmp/cca112771.o: In function `main':
>>/tmp/cca112771.o(.text+0xcc9): undefined reference to `sin'

>>I have math.h #include 'd in my code.
>>I've tried *ptr=sin, but that doesn't work, it gives me an invalid lvalue in
>>assignment error.
>>I've also tried doing cc prints.c -lm, which unfortunately did not
>>work.

>>Any ideas?
>>Thanks.

>including the header is not enough..
>are you also linking in the lib?

>perhaps.. -dlibmath

rereads the original post to see if His brilliant (NOT) suggestion was appreciated
perhaps -lm  :-|

doh!

--
*/ unmatched closing comment



Sat, 09 Mar 2002 03:00:00 GMT  
 
 [ 13 post ] 

 Relevant Pages 

1. How to use (pointer to function), and function and pointer to (pointer to function)

2. Assigning structure pointer to function pointer

3. C++ function pointers versus C function pointer problem

4. Pointer Functions and Pointers to Pointer Functions

5. Assigning "putchar" to a function pointer

6. Assigning "putchar" to a function pointer

7. Inherited class function calls from a pointer assigned to the base class

8. Question about signal()/pointers to functions that return pointers to functions

9. function pointers and function pointers array

10. Pointer to function returning pointer to function returning...

11. Problem passing char * to a function where it is assigned its value

12. Class function pointer does not evaluate to a function

 

 
Powered by phpBB® Forum Software