Announcement

Collapse
No announcement yet.

Selective Compiling

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

  • Selective Compiling

    Can the #IF statement be used inside the source code?

    The concept is to control which parts of the code are compiled based on the contents of an include file. The purpose of this exercise is to allow a master source code file that can be customized by allowing only the selected sections to be compiled.

    What I'm trying to accomplish is not having to maintain more that one source code file.

    Any suggestions or comments would be appreciated.

  • #2
    Can the #IF statement be used inside the source code?
    Yes, where else would it be used or did you mean "inside a sub/function"? The #if/#else/#endif conditional compilation keywords can be used almost anywhere in your code. I use it in all my projects.
    kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

    Comment


    • #3
      I use #IF %DEF(%USE_xxxxx) around all the Functions(or code blocks) in a very large include file. It's the best way to get granularity with PB.

      James

      Comment


      • #4
        I would use separate INC files (and I do) each with its own #IF wrapper, in case one is Dependant on another (or not)... That way depending on the project, I can either comment, or uncomment a couple of lines, and it all works fine.
        (especially for larger projects)
        Engineer's Motto: If it aint broke take it apart and fix it

        "If at 1st you don't succeed... call it version 1.0"

        "Half of Programming is coding"....."The other 90% is DEBUGGING"

        "Document my code????" .... "WHYYY??? do you think they call it CODE? "

        Comment


        • #5
          Thank You Gentlemen.

          I had gotten the impression that Meta Statements (i.e. #IF) had to be used prior to the begining of the code. Apparently they are far more flexible than I thought.

          Cliff;
          I had thought of using separate includes. It's nice to know that technique will work.

          Comment


          • #6
            Walter,
            I take things a step farther too, that I do not see often (if ever) in any language (except those that handle it for you), that in larger projects, I group *.INC files by category so I can more easily find it later (after many years of not looking at the code)

            Stuff like (bad example but you will get it), lets say you use Win32Api.INC, and CommonCtrls.INC, and Kernel32.INC (bogus name to my knowledge), and group them into a folder called "WindowsFunctions"

            For the sake of argument lets say Win32Api.INC depended on Kernel32.INC function then not only do you have a category to look for, but can settle odd compiling errors.

            Stuff like
            #INCLUDE "./WindowsFunctions/Win32Api.INC"

            and in it I have
            #IF NOT DEF "Kernel32.INC"

            sort of thing.

            Its a bit unorthodox, but found no troubles so far, and makes things more "modular' in my mind
            Engineer's Motto: If it aint broke take it apart and fix it

            "If at 1st you don't succeed... call it version 1.0"

            "Half of Programming is coding"....."The other 90% is DEBUGGING"

            "Document my code????" .... "WHYYY??? do you think they call it CODE? "

            Comment


            • #7
              For the sake of argument lets say Win32Api.INC depended on Kernel32.INC function then ....
              ... then you should set up Win32API.INC to #INCLUDE Kernel32.INC if not already included. eg.

              Code:
              ' FILE: Win32API.INC
              #IF NOT %DEF (%KERNEL32_INC)
                #INCLUDE "KERNEL32.INC"
              #ENDIF
              ....
              ....
              ' File: KERNEL32.INC
              %KERNEL32_INC = 1 
              ...
              %Equate_1 = 1
              DECLARE FUNCTION_1 ...
              
              ....
              Most if not all the "factory" versions of the Windows' header files come from Florida with all these "#IF %DEF(xxxx)" set up for you.

              When building your own "family" of #INCLUDE files, you have to set this stuff up yourself.

              That said, the compiler is very forgiving of duplicates, not throwing an error if you #INCLUDE the same file twice; only throwiing an error if an equate, UDT or DECLARE contains a mismatch with a prior definition.

              MCM
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment

              Working...
              X