This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Library function reentrancy?

I'm sure it's written somewhere and I'm not opposed to looking for it. However I have looked and found nothing so I'll ask.

There are a host of "behind the scenes" library functions that perform such magic as right or left shifts of various data types, etc. Even the ubiquitous switch() statement compiles into a special library call (LCALL ?C?CCASE) to do the work. My (probably paranoid) concern is the degree to which these functions may be employed in an interrupt routine.

I'm concluding that since none of my programs crash miserably that it's OK to use any "c" construct in an interrupt routine and that the behind the scenes library functions are designed for reentrancy.

It would just be nice to find that in print somewhere. Thanks for reading & commenting.
Steve C.

Parents
  • Library may not be the exact term you are looking for. They would be functions requiring includes. And not all of those are re-entrant. Normal C key words work in reentrant functions. However go take care about how much work you do in an interrupt. those calls may cause the compiler to push a lot of stuff on the stack. that and call can kill interrupt performance.

Reply
  • Library may not be the exact term you are looking for. They would be functions requiring includes. And not all of those are re-entrant. Normal C key words work in reentrant functions. However go take care about how much work you do in an interrupt. those calls may cause the compiler to push a lot of stuff on the stack. that and call can kill interrupt performance.

Children
  • Thanks Neil,

    I think library is exactly the term I'm looking for. However, it needs to be stated that there are sort of 2 libraries here.

    1. The ANSI C standard library routines (requiring header files, STDIO.H, etc., functions like printf(), isalpha(), etc.) and
    2. The underlying run time library functions that implement pointer conversions, switch statement logic, integer division, rotates, shifts, etc.

    All of these functions are found in the Keil library files (such as C51S.LIB) but only the published ANSI functions (as listed in the various header files) are really directly user accessible. My concern is with the other "hidden" functions. It's not always clear when and how they will get invoked.

    For example, a switch() statement (my previous example) will invoke CCASE. A statement like "i = 0x8422 << 7" may invoke some helper shift function as well.

    It's widely understood that interrupt routines should contain as little code as possible for performance reasons. I'm concerned about the nature of that code, not the amount.

    Again it would be nice to some some printed assurance regarding this point.

    Thanks for the reply.
    Steve C.

  • These are documented in the "Routines By Category" section of the C51 User's Guide.

    http://www.keil.com/support/man/docs/c51/c51_lib_routines.htm

  • "These are documented in the "Routines By Category" section of the C51 User's Guide"

    That covers only the "public" functions from the standard ANSI library (and some Keil intrinsics) - not the "hidden" helper functions that the OP was actually after:

    "The underlying run time library functions that implement pointer conversions, switch statement logic, integer division, rotates, shifts, etc."

    Since there are no warnings about reentrancy issues with these, one would hope that there are no issues - but, as the OP said, it would be nice to have it in black and white...!

  • The run-time routines in the library use only registers and are therefore reentrant.

    Jon

  • Thanks Andy,

    You understand the question.

    Jon,
    The run-time routines in the library use only registers and are therefore reentrant.

    Are you refering to the hidden functions that I'm talking about? If so, what is the basis for your comment? I too can conclude that the functions must be reentrant or we'd all be in a world of hurt. But where does it say that?

    According to the link that Dan posted (http://www.keil.com/support/man/docs/c51/c51_lib_routines.htm) - and what I also found in the C51 manual:
    Many of the routines in the C51 standard library are reentrant and/or intrinsic.

    Many, but not ALL. And it says nothing of the of the other hidden functions.

    Thanks for all of your replies.
    Steve C.

  • "According to the link that Dan posted (http://www.keil.com/support/man/docs/c51/c51_lib_routines.htm) - and what I also found in the C51 manual:
    Many of the routines in the C51 standard library are reentrant and/or intrinsic."

    If you read the two sentences following that you will understand how to find out *which* routines are reentrant:

    <Many of the routines in the C51 standard library are reentrant and/or intrinsic. These specifications are listed in the following tables. Unless otherwise noted, routines are non-reentrant and non-intrinsic.>

    "And it says nothing of the of the other hidden functions."

    Why do you care if the hidden functions are reentrant? Why would there be any need to know if they are reentrant?

  • "Jon, ... what is the basis for your comment?"

    I think Jon has inside information... ;-)

  • OK,
    Duh, my bad.

    Sorry, Jon. Did a little research and I learned that you work for Keil. Thanks for the help :)
    Steve C.