No announcement yet.

call stack

  • Filter
  • Time
  • Show
Clear All
new posts

    call stack

    hello people,

    i'm looking for a way to access the call stack in powerbasic dos.
    i have some routines that need to behave differently depending on where
    they were called from, so i need to know the name of the routine(s) that
    performed the call (or take a look at the entire call stack to find
    a specific routine).
    i can also check the calling routine by passing vars but i'm sure there
    is a more elegant way to do this. thanx for any tips on this.



    There is no way that I know of in any compiled language to programmatically determine the symbollic name of the calling routine. I know that when the object file is compiled with debugging symbols turned on for the sake of debugging that such information is actually known, but I've only seen debuggers use that information, not the programs themselves.

    Offhand, I'd guess that what you wish to do is most likely not possible from any compiled language that I know of. Even in languages where introspection is available (such as Java and C#), I doubt it would return this kind of information

    I don't know what you are trying to accomplish, but generally speaking changing the behavior of a subroutine based on who called it is probably not a good idea. At the very least debugging your code down the road would be very difficult if you forgot why you did something. In short, the behavior of the subroutine is best controlled by known parameters, not some other magic input.



      A crude way to do this is to pass whatever ID information you need
      to a disk file. You read the disk file in when the call is made.
      You know the information needed. Obviously, to do this you need to
      be the one writing both (all) sides of the equation.

      Another way to get this might be to exit the calling routine with
      a specific error level set in DOS. The next mission after that may
      be able to read the DOS error set, act accordingly.

      Again, you'd have to have control over the calling code as well to
      pull this off.. Just an idea.

      Mike Luther
      [email protected]
      Mike Luther
      [email protected]


        can also check the calling routine by passing vars but i'm sure there is a more elegant way to do this.
        This <U>is</U> the most elegant way to do this, especially if you ever, ever ever might change the routine.

        When I have a more-or-less common routine which has to do some things a little differently, I just add an 'action' parameter...

        FUNCTION Foo (BYVAL Action AS LONG, parm1 AS whatever, parm2 as whatever) AS LONG
           SELECT CASE action
              CASE %ACTION_SUSPEND
            END SELECT
            (Code common to all, except you have set any action-dependent variables already)

        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]