Home AMX User Forum AMX General Discussion

Why doesn't this work?

viningvining X MemberPosts: 4,368
DEFINE_START

nVST_DeBug = 0 ;  // use to debug from start up!  change to 0 when finished debugging!
if (nVST_DeBug)   // or comment out completely !
     {
     #WARN 'nVST_DeBug is set to 1 in DEFINE_START' ;
     }

No matter what I change nVST_DeBug to I get the compiler warning, which is not what I expected!

Why?

Comments

  • Joe HebertJoe Hebert Junior Member Posts: 2,159
    The short answer is because that?s its job. It?s a precompile directive. Unless there is some other precompile directive wrapped around it (i.e. #IF_DEFINED, #IF_NOT_DEFINED, etc.) the warning message will be generated at compile time. The compiler doesn?t evaluate IF conditions. IF conditions are evaluated at run-time. Precompile directives are not evaluated at run-time, they are evaluated at compile time.
  • Joe HebertJoe Hebert Junior Member Posts: 2,159
    As a follow up, you could do something like this:

    Debug is on and will generate your warning ? at compile time
    DEFINE_CONSTANT
    
    INTEGER nDebugOff = 0
    INTEGER nDebugOn  = 1
    
    DEFINE_VARIABLE
    
    INTEGER nDebug
    
    DEFINE_START
    
    nDebug = nDebugOn
    
    #IF_DEFINED nDebugOn
       #WARN 'Debug in On'
    #END_IF
    

    And to turn debug off and not have the warning generated you could do this:
    DEFINE_CONSTANT
    
    INTEGER nDebugOff = 0
    //INTEGER nDebugOn  = 1
    
    DEFINE_VARIABLE
    
    INTEGER nDebug
    
    DEFINE_START
    
    nDebug = nDebugOff
    
    #IF_DEFINED nDebugOn
       #WARN 'Debug in On'
    #END_IF
    

    HTH
  • DHawthorneDHawthorne Old Timer Posts: 4,584
    It should be noted that Joe's examples require a re-compile to turn the debug flag on and off, you can't use precompiler directives on-the-fly.

    I've found it simpler to use SEND_STRING 0 coupled with a regular variable (or virtual device channel). Precompiler directives are a bit kludgy for this kind of application, IMO.
  • Joe HebertJoe Hebert Junior Member Posts: 2,159
    DHawthorne wrote:
    It should be noted that Joe's examples require a re-compile to turn the debug flag on and off, you can't use precompiler directives on-the-fly.
    Yes, you do have to recompile if you modify source code. :) Isn?t that what this thread is about ? compile time? Thought I did note that:
    me wrote:
    Precompile directives are not evaluated at run-time, they are evaluated at compile time.
    DHawthorne wrote:
    I've found it simpler to use SEND_STRING 0 coupled with a regular variable (or virtual device channel). Precompiler directives are a bit kludgy for this kind of application, IMO.
    Agreed. The example is there to show how the directive works answering the original question posed. A debug channel normally suffices for me too.
  • viningvining X Member Posts: 4,368
    Joe wrote:
    Unless there is some other precompile directive wrapped around it (i.e. #IF_DEFINED, #IF_NOT_DEFINED, etc.)
    That's what I suspected.

    DHawthorne wrote:
    I've found it simpler to use SEND_STRING 0 coupled with a regular variable (or virtual device channel). Precompiler directives are a bit kludgy for this kind of application, IMO.
    I have a regular debug variable used through out the code as a conditon for enabling or disabling my SEND_STRING 0's which is the var nVST_DeBug. I just wanted a lazy mans way of starting debug at start up just so I can see all the initialization stuff that I would miss if I'm slow on the trigger. The #WARN was put there as a reminder that I set it in DEFINE_START and not by setting a variable or channel.
Sign In or Register to comment.