"Saroj" <sa*************@gmail.com> writes:
Is there an way for a function to know who called him ?
Not portably. Some specific environments have specific
solutions; for example, if you are using the GNU C library, you
might be able to find out with backtrace(), but even that won't
always tell you the correct answer.
In some cases there might not even be a way to find out. For
example, if the function that called the current function did so
as its last action, then the compiler might have emitted a "jump"
instruction instead of a "call" instruction, which in turn would
have erased all the obvious evidence that it was the function
that did the call. But even the possibility for this is system
specific.
--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}