avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] Finding address of where a function called from


From: Tom Harris
Subject: [avr-gcc-list] Finding address of where a function called from
Date: Thu, 29 Jan 2004 15:51:24 +1100

Greetings,

For logging purposes I would like the called function to be able to find out
where it was called _from_. What I have done in the past is to take the
address of a dummy variable on the stack, add a bit to it and hope that the
result is the address of the stack with the return in it. Sort of the code
below (which is off the top of my head and probably doesn't even compile):

#define FIDDLE_FACTOR 4
void foo() {
        char dummy;

        uint16_t* whereCalled = *((uint16_t*)(&dummy) + FIDDLE_FACTOR);

        ...
}

The problem is that as the number of stack reserved for the use of foo()
changes, so does the size of FIDDLE_FACTOR. Is there a more portable way of
determining this?

TomH


reply via email to

[Prev in Thread] Current Thread [Next in Thread]