Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function pointers lead to missing function name in Data.xml #683

Open
lukasrothenberger opened this issue Nov 8, 2024 · 0 comments
Open
Labels
invalid This doesn't seem right

Comments

@lukasrothenberger
Copy link
Collaborator

lukasrothenberger commented Nov 8, 2024

Problem:
Missing function name in Data.xml for the call func_ptr_arr[1](); in Data.xml.
Solution:
Gather the missing information during runtime and instantiate the dummy call accordingly.
Sample Code:

#include <iostream>

void a(){
    std::cout << "a" << std::endl;
}

void b(){
    std::cout << "b" << std::endl;
}

int main(){
    // declare array of function pointers
    void (*func_ptr_arr[2])() = {a, b};

    // call function b
    func_ptr_arr[1]();
}

More advanced sample code:

#include <iostream>

void a(){
    std::cout << "a" << std::endl;
}

void b(){
    std::cout << "b" << std::endl;
}

int main(){
    // declare array of function pointers
    void (*func_ptr_arr[2])() = {a, b};

    // get random index
    srand((unsigned)time(0)); 
    int i = rand() % 2;
    std::cout << "i: " << i << std::endl;
    
    // call function
    func_ptr_arr[i]();
}
``
@lukasrothenberger lukasrothenberger added the invalid This doesn't seem right label Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

1 participant