-
Notifications
You must be signed in to change notification settings - Fork 82
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
stub function will not be called when two nested functions in the same file #26
Comments
What are the compile options? |
cmake |
It's optimized by the compiler. main.cpp #include"stub.h"
#include <iostream>
int fun1(int a);
int fun2(int a);
int test_stub(int a){
std::cout << "test_stub" << std::endl;
return 0;
}
int main(){
Stub stub;
stub.set(fun1, test_stub);
fun2(1);
return 0;
} test.cpp int fun1(int a){return a;}
int fun2(int a){ return fun1(a);}
|
Thank for your answer. However, I still have the same issue with -O0. My functions are much more complex than the ones in the above example so the compiler cannot remove fun1. |
Give me an example of a problem so I can analyze it. |
I think the above example can show the issue. With the command: "g++ test.cpp main.cpp -o main" and "./main" has a seg fault. But if I separate the two functions in different files test1.cpp and test2.cpp, then it works well. test1.cpp test2.cpp |
In the following example, test_stub will not be called. But test_stub will be call when fun1 and fun2 are in two diff files.
main.c:
int test_stub(int a){
return 0;
}
stub.set(fun1, test_stub);
fun2(1);
test.c:
fun1(int a){return a;}
fun2(int a){ return fun1(a);}
The text was updated successfully, but these errors were encountered: