Announcement

Collapse
No announcement yet.

Unit Question

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

  • Unit Question

    Greetings All!

    I've recently moved some of my modularized code into an external unit and I’m pleased with the smaller source file. It took me a bit to iron out a few of the wrinkles but some of the information found on page 151 of the User’s Guide did help. I’m left with a couple of questions though:

    1. Is it possible for a SUB to make a call on another SUB that is contained within the same unit?

    2. If there are unused SUBs or FUNCTIONs within the unit are they still part of the finished compiled program? If so, is there any method or program to sift through and find what isn’t being used?

    ...also, if anyone has any tips or warnings to throw at me about units I’d appreciate it.


    ------------------
    Don Ewald
    mailto:[email protected][email protected]</A>
    Donnie Ewald
    [email protected]

  • #2
    As long as you $link or $include the units to the main program
    while compiling:

    1. Yes. As long as the SUB's are not nested (which is bad practice
    anyway).

    2. Yes. You can conditionally compile. If you find an unused code
    segment you can:

    $if 0
    Unused code
    Unused code
    $endif

    The code between the "$"'s will not be compiled or included in
    the finished product.

    I seem to recall somewhere that there are program(s) that will
    sift source codes and weed out unused segments. Can't remember
    where they are. Sorry.

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


    [This message has been edited by Mel Bishop (edited August 30, 2001).]
    There are no atheists in a fox hole or the morning of a math test.
    If my flag offends you, I'll help you pack.

    Comment


    • #3
      Originally posted by Mel Bishop:
      1. Yes. As long as the SUB's are not nested (which is bad practice
      anyway).
      To be clear, you can certainly call a Sub from another Sub which calls another Sub, and so on. However, you cannot create a Sub within another Sub.
      ...between the "$"'s...
      Well, to be more specific, if the $IF argument evaluates to zero at compile-time, then the text following is excluded from the compilation. See $IF/$ELSEIF/$ELSE/$ENDIF for more information.

      To locate redundant variables and Sub/Function blocks, checkout the DOWNLOADS area - there are one or two cross-reference tools in there.
      www.powerbasic.com/files/pub/pbdos/

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

      Comment


      • #4
        Nesting subs is not necessarily bad practice but, since PowerBASIC doesn't support nested routines, it's a moot point.

        Unused subs or functions will still be part of your compiled code. However, if you put the units into .PBL libraries, PowerBASIC will only use the units in the .PBL that are needed by your code.

        You can find many fine tools for PowerBASIC programming right here, in the download section: http://www.powerbasic.com/files/pub/


        ------------------
        Tom Hanlin
        PowerBASIC Staff

        Comment


        • #5
          About Point One from above, I tried to generate a unit file that had my complete subroutines and functions; but one had problems. One of the SUBs called on another SUB found within the same unit and nothing fired off. If it was a known issue, I'm sure it would have been brought to my attention here, so I played around with the code and met with no success.

          Finally, I cut the SUBs from the compiled unit and placed them back into the main source file. After reading of no known issues here, I moved the code back to the unit and pasted it at the end. Suddenly, things worked! I must've made a change somewhere or something.

          I really liked Tom's suggestion of creating individual units and compiling them into a library. I don't know how to do it yet; but, I'm sure I'll stumble through it.

          Unfortunately, I don't quite understand the use of conditional compiles; so, I'll assume that I've no need for it right now. Thanks for the thoughts.


          ------------------
          Don Ewald
          mailto:[email protected][email protected]</A>
          Donnie Ewald
          [email protected]

          Comment


          • #6
            Hi Don

            You posted:

            ------------------------------------------------------------------------------------------------------------------
            Unfortunately, I don't quite understand the use of conditional compiles; so, I'll assume that I've no need for it right now. Thanks for the thoughts.
            -------------------------------------------------------------------------------------------------------------------

            Let me ask you this: How many times have you had to REMark out
            lines of code in order to de-bug a program? I know you've had
            to do it on more than one occasion.

            If you have, for example, 6 lines to REM out, then instead of
            using 6 REM's, use the conditional compile option as noted above.
            This does the EXACT same thing and saves a huge amount of time.



            ------------------
            There are no atheists in a fox hole or the morning of a math test.
            If my flag offends you, I'll help you pack.

            Comment

            Working...
            X