Function Traceback
-
Hi All, Is there a way to know the reference to the calling function at runtime without using some flag variables? For eg.
void foo() { foobar(); } void bar() { foobar(); } void foobar() { /* What will be the condition for this IF? */ if (calling function is 'foo') { bla... bla.. } else { bla... bla.. } }
Thanks. -
Hi All, Is there a way to know the reference to the calling function at runtime without using some flag variables? For eg.
void foo() { foobar(); } void bar() { foobar(); } void foobar() { /* What will be the condition for this IF? */ if (calling function is 'foo') { bla... bla.. } else { bla... bla.. } }
Thanks.The only thing I can think of it to pass an argument to the
foobar()
function.
"Take only what you need and leave the land as you found it." - Native American Proverb
-
The only thing I can think of it to pass an argument to the
foobar()
function.
"Take only what you need and leave the land as you found it." - Native American Proverb
DavidCrow wrote:
The only thing I can think of it to pass an argument to the foobar() function.
Thanks David. But maybe I did not put my question correctly. I have a library and I want to hide a function from direct calling by functions which are external to the library. Kind of like keeping it in private: section of a C++ class. But the problem is, I want the library in pure C and not C++. So, my library function 'foo()' should be able to invoke foobar() correctly. However, if an external function bar() tries to invoke it, the library should be able to correctly identify it and return appropriate error. Appreciate your help.
-
DavidCrow wrote:
The only thing I can think of it to pass an argument to the foobar() function.
Thanks David. But maybe I did not put my question correctly. I have a library and I want to hide a function from direct calling by functions which are external to the library. Kind of like keeping it in private: section of a C++ class. But the problem is, I want the library in pure C and not C++. So, my library function 'foo()' should be able to invoke foobar() correctly. However, if an external function bar() tries to invoke it, the library should be able to correctly identify it and return appropriate error. Appreciate your help.
Even with these new constraints, my suggestion will still work. All you have to do is choose a number to pass to the exported
foobar()
function that will likely not be guessed by others.
"Take only what you need and leave the land as you found it." - Native American Proverb
-
DavidCrow wrote:
The only thing I can think of it to pass an argument to the foobar() function.
Thanks David. But maybe I did not put my question correctly. I have a library and I want to hide a function from direct calling by functions which are external to the library. Kind of like keeping it in private: section of a C++ class. But the problem is, I want the library in pure C and not C++. So, my library function 'foo()' should be able to invoke foobar() correctly. However, if an external function bar() tries to invoke it, the library should be able to correctly identify it and return appropriate error. Appreciate your help.
I'm not certain that you can hide functions in a library; hackers will find the name and arguments for it in the library ( but I might be wrong ) If the function is not "published" in a header file, a
normal
user will not call it.
Maximilien Lincourt Your Head A Splode - Strong Bad
-
Even with these new constraints, my suggestion will still work. All you have to do is choose a number to pass to the exported
foobar()
function that will likely not be guessed by others.
"Take only what you need and leave the land as you found it." - Native American Proverb
DavidCrow wrote:
Even with these new constraints, my suggestion will still work. All you have to do is choose a number to pass to the exported foobar() function that will likely not be guessed by others.
You are right. That is a Workable solution. Thanks David.
-
I'm not certain that you can hide functions in a library; hackers will find the name and arguments for it in the library ( but I might be wrong ) If the function is not "published" in a header file, a
normal
user will not call it.
Maximilien Lincourt Your Head A Splode - Strong Bad
-
I'm not certain that you can hide functions in a library; hackers will find the name and arguments for it in the library ( but I might be wrong ) If the function is not "published" in a header file, a
normal
user will not call it.
Maximilien Lincourt Your Head A Splode - Strong Bad