In article <dn************@news.flash-gordon.me.uk>,
Flash Gordon <sp**@flash-gordon.me.ukwrote:
>Asbjørn Sæbø wrote, On 09/01/08 21:37:
>Ben Pfaff <bl*@cs.stanford.eduwrites:
>>Why are you replacing functions with macros? It sounds like
functions are more appropriate for this use case.
>Indeed they are, except for the fact that I am working on an embedded
platform and having "multiple call" problems, with functions being
called both from main() and from interrupts. Replacing functions with
macros is one step towards one way of solving this.
>It is a truly horrible way of solving it in my opinion. Better ways
would include:
Making the functions safely re-entrant
Making the functions inline if your compiler supports this
As the poster mentioned in another part of this thread that his
embedded system has no stack, my *speculation* was that it does not
have "return addresses" for functions, and the compiler is doing
a static branch to the function and static return -- which would
only allow each function to be called once. (Which doesn't explain
how the standard library would work, but since it is an embedded
system at least the poster would not have I/O portion of the
standard library to be concerned with.)
If this speculation were correct, it would be consistant with
"local variables" being possible if the compiler in question
ended up allocating the "local variables" at (possibly overlapping)
fixed addresses.
The result would not be consistant with the C standards in that
it would not allow recursion, but that might not be a problem
in that application environment.
This kind of construct of "no stack" could be extended to handle
multiple calls to the same routine if instead of using static
return addresses, the compiler used the equivilent of the old
IBM 360 BALR (Branch and Link Register), in which the return address
was put into a specific register instead of being put onto a
"stack". Multiple call levels could be handled by storing the
old return address in the fixed-addressed (possibly overlapped)
local variables possibility mentioned above. On the other hand,
I cannot think right at the moment why this would present problems
with "multiple calls" or ISRs.
--
"Okay, buzzwords only. Two syllables, tops." -- Laurie Anderson