Announcement

Collapse
No announcement yet.

Use of labels in PB/DLL

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Use of labels in PB/DLL

    I would just like a clarification on the scoping rules for labels.

    It appears that labels are local to SUBs/FUNCTIONs as long as they
    are referenced via GOTO/GOSUB, but global when referenced via
    assembly jump instructions.

    I've had to make all labels referenced via my inline assembler
    routines unique while labels referenced via PB/DLL statements
    are not (necessarily) unique.

    I didn't see any explanation for using unique labels with ASM
    instructions in the manual...



    ------------------
    Bernard Ertl
    Bernard Ertl
    InterPlan Systems

  • #2
    Bern,

    One could alleviate this problem by not using labels in the
    high level programming portions of your modules. I know you
    probably don't want to hear it but all high level programming
    languages discourage this practice. I used to do the label
    gig a long time ago, but no longer.

    Assembler, on the other hand, it's a necessary evil. However,
    it's usually easier to follow in asm notation than standard
    Basic or C/C++ or whatever coding.

    Personally, nothing is more irritating than trying to follow
    labels stuck all over the place. Give me procedures (subs
    or functions)any day. Just a programming preference!!!!

    Cheers,
    Cecil

    ------------------

    Comment


    • #3
      Originally posted by Bern Ertl:
      I would just like a clarification on the scoping rules for labels.

      It appears that labels are local to SUBs/FUNCTIONs as long as they
      are referenced via GOTO/GOSUB, but global when referenced via
      assembly jump instructions.
      I can confirm you observation. Found out the hard way too..

      ------------------
      Best Regards
      Peter Scheutz
      Best Regards
      Peter Scheutz

      Comment


      • #4
        R&D advise that in the next update to the compiler, labels will be 100% local in scope, even to inline assembler code. It would not be wise to exploit the current ability unless you don't want to be able to recompile in the future.

        ------------------
        Lance
        PowerBASIC Support
        mailto:[email protected][email protected]</A>
        Lance
        mailto:[email protected]

        Comment


        • #5
          Bern,

          Using unique labels is still a necessity in this version as most
          of us have found out but Lance mentioned that later versions will
          make labels local to each procedure which in most instances will
          make label usage easier to manage.

          I know where Cecil is coming from as I have seen some really badly
          written code that had badly named labels all over the place. Problem
          is that there are many tricks in speed terms, even in high level
          language where exiting a loop with a GOTO is just more efficient
          so I am inclined to use long label names so I know what they are
          for.

          Your worst nightmare is a multi level deep loop with labels like
          X: Y: etc.. which are non referential.

          I prefer labels named like Loop_Start: Loop_Exit: so that you
          can use code like
          Code:
          If [condition] Then GOTO Loop_Exit
          and you don't get the problem of unintelligible locations.

          Regards,

          [email protected]

          ------------------
          hutch at movsd dot com
          The MASM Forum - SLL Modules and PB Libraries

          http://www.masm32.com/board/index.php?board=69.0

          Comment


          • #6
            Everyone,

            Thanks for the clarification.

            I too prefer not to use labels, but sometimes it is necessary.




            ------------------
            Bernard Ertl
            Bernard Ertl
            InterPlan Systems

            Comment

            Working...
            X