avr-chat
[Top][All Lists]
Advanced

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

Re: [avr-chat] re-entrant functions


From: David Brown
Subject: Re: [avr-chat] re-entrant functions
Date: Wed, 1 Feb 2006 09:28:27 +0100

AW: [avr-chat] re-entrant functionsIt is not compiler dependant - it is
dependant on the compiler being a proper C compiler.  The Keil C51 compiler,
like many compilers for horrible CISC 8-bit cpus, is not a proper C
compiler - it makes changes to the language and to the implementation of the
language in order to generate small, fast code for the majority of code.
This in itself is not a bad idea - code generated by a complient C compiler
on an 8051 would of necessity be very poor code.  In this case, the problem
is that the 8051 has very few registers, and extremely slow data stack
access, so parameters and local variables are generally held in hidden
global variables for speed.  Thus the code is not re-entrant.

For compilers that conform to C standards, like avrgcc, there is no problem.
There are only two restrictions that a function must conform to to be
re-entrant - it should be extremly careful with global or static data (or
avoid them altogether, for safety), and any other functions it calls must
also be re-entrant.

Note that recursive functions, mentioned by Derric Tubbs, are merely a
subset of re-entrant functions, and the same rules apply.

mvh.,

David



----- Original Message -----
From: Stumpf Michael
To: address@hidden
Sent: Wednesday, February 01, 2006 8:05 AM
Subject: AW: [avr-chat] re-entrant functions

:
:developer2112 (sent by Nabble.com) wrote:
:> Are re-entrant functions supported in winavr? If so, how does one go
:> about writing one? Is there some reentrant keyword that will
:cause the
:> compiler to use the stack for passing parameters instead of fixed
:> registers?
:
:Just because registers are used for parameter passing, doesn't make a
:function any less re-entrant. To be re-entrant, just don't
:store persistant
:state in the function such as with static variables.
:
It is compiler dependent.
I remember the Keil C51 compiler to generate non-reentrant code,
because lacal variables were stored in fixed memory locations
rather than on the stack. To make a function reentrant a special keyword
'reentrant' had to be applied to it.
But that was a very special case, no?
Winavr does generate reentrant code with no extra effort.
Recursive functions are only one kind of reentrant functions
regards, Michael



:_______________________________________________
:AVR-chat mailing list
:address@hidden
:http://lists.nongnu.org/mailman/listinfo/avr-chat
:



_______________________________________________
AVR-chat mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/avr-chat





reply via email to

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