Skip to content

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

@lukasrothenberger

Description

@lukasrothenberger

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]();
}
``

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidThis doesn't seem right

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions