2

I am trying to store and use a pointer to a global function. The function global_f returns a String and takes an object as parameter:

String global_f(Request r){
    // ...
    return "This is it";
}

I have also declared a type:

typedef String (*f_type)(Request);

And this is the class that stores the function:

class T {
    f_type f;

    void setF(f_type fFunc){ // called as: setF(&global_f)
        f = fFunc;
        f(Request());        // This Works
    }

    void callF(){
        f(Request());       // This Freezes the arduino
    }
}

So I can call f in the instructor, but it freezes the Arduino in other methods.

Follow-up: It runs in all methods, that the function is being passed as a parameter and stored in the object. This is where this functions is called in the actual code: GitHub

6
  • //called as: T(&global_f)? it should be T(global_f)
    – Juraj
    Mar 1 '19 at 20:34
  • how do you know it is freezing the Arduino? or even working in the first case? You don't do anything with the return value in either case!; can you make a complete, minimal sketch that shows the problem?
    – esoterik
    Mar 1 '19 at 20:41
  • @Juraj I tried both of them and they give the same results, also PlatformIO compiles both
    – Kostas C.
    Mar 1 '19 at 21:20
  • @esoterik I am using Serial.print to know how it runs. This is just the most important part of the code for this problem. I can provide a link to github if it is needed.
    – Kostas C.
    Mar 1 '19 at 21:25
  • 1
    @Juraj This is the actual code I'm using github.com/kachatzis/ArduinoWebServer/blob/…
    – Kostas C.
    Mar 2 '19 at 17:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.