Frederick Gotham <
cauldwel...@gmail.com> wrote:
> There's a function that must behave a little differently if it's called
> from a **particular** function in a **particular** thread.
With particular thread it's simple, just store thread ID and compare it
later. With function it gets tricky.
Can you edit the header included from the file that you cannot modify? If
yes, maybe instead of a function prototype, write a macro that will check
__FUNCTION__ variable, or just call your function (that you can modify)
with __FUNCTION__ as an argument.
Something like this:
#v+ test.cpp
#include <string>
#include <cstdio>
// prototype which you can modify (in header)
#define myFunction() myFunction2(__FUNCTION__)
// function that you can modify
void myFunction2(const std::string& functionName)
{
if (functionName == "main")
printf("Called from main\n");
else
printf("Not called from main, called from %s instead\n",
functionName.c_str());
}
// function that you cannot modify
void fn()
{
myFunction();
}
// function that you cannot modify
int main()
{
myFunction();
fn();
return 0;
}
#v-
--
https://www.youtube.com/watch?v=9lSzL1DqQn0