RE: Can you use C function pointers like you'd use LISP lambda?

by (Login ComputerGhost)
R

I don't know lisp, but I've used C. Nested functions aren't standard C++, but gcc does support them as an extension. I could not get your code to compile, but I've studied it a little and will venture a guess as to what is happening.

Here is what I think is happening:

There is only one foo function. In main, when you call compose, a pointer to that one foo function is returned. When you call twoplus (aka foo): by coincidence, the memory taken up by a and b (inside of compose) has not been changed from pointing to oneplus; so foo calls oneplus(oneplus(x)) agan.

If you call compose again with another value, I don't think twoplus will work as intended anymore because the values at the memory that a and b (inside of compose) use will change. I'd try this to see if I am right or wrong.

Posted on Jul 6, 2009, 11:19 AM

Respond to this message   

Return to Index


Response TitleAuthor and Date
I did the tests like you said, and there is indeed only one function createdqbguy on Jul 6