Home AMX User Forum NetLinx Studio

Pre-processor directive bug

This illustrates one of the bugs with the NetLinx compiler pre-processor which I find very frustrating.

Consider this program:
PROGRAM_NAME='master'
#define __A_TOKEN__ 'A Token'
#if_defined __ANOTHER_TOKEN__
    #warn 'Warning!'
#end_if

Obviously, the warning should not be thrown at compile time (as __ANOTHER_TOKEN__ is not defined) and indeed it isn't.

Given the logic above which seems to indicate that nesting compiler directives is OK, the following should be acceptable:
PROGRAM_NAME='master'
#define __A_TOKEN__ 'A Token'
#if_defined __ANOTHER_TOKEN__
    #define __A_TOKEN__ 'Same Token'
#end_if

Although the second #define statement should never be reached, the compiler fails with the error message:
ERROR: [path]\master.axs(4)Symbol '__A_TOKEN__' is already defined

The same error is thrown for the following:
PROGRAM_NAME='master'
#define __A_TOKEN__ 'A Token'
#if_not_defined __A_TOKEN__
	#define __A_TOKEN__ 'Same Token'
#end_if

I would dearly love to see this fixed!

Comments

  • DHawthorneDHawthorne Posts: 4,584
    If I had to guess, I'd say it scans for #DEFINEs all at once on a primary pass, disregarding #IFs until a later pass.
  • ericmedleyericmedley Posts: 4,177
    Auser wrote: »
    This illustrates one of the bugs with the NetLinx compiler pre-processor which I find very frustrating.

    Consider this program:
    PROGRAM_NAME='master'
    #define __A_TOKEN__ 'A Token'
    #if_defined __ANOTHER_TOKEN__
        #warn 'Warning!'
    #end_if
    

    Obviously, the warning should not be thrown at compile time (as __ANOTHER_TOKEN__ is not defined) and indeed it isn't.

    Given the logic above which seems to indicate that nesting compiler directives is OK, the following should be acceptable:
    PROGRAM_NAME='master'
    #define __A_TOKEN__ 'A Token'
    #if_defined __ANOTHER_TOKEN__
        #define __A_TOKEN__ 'Same Token'
    #end_if
    

    Although the second #define statement should never be reached, the compiler fails with the error message:
    ERROR: [path]\master.axs(4)Symbol '__A_TOKEN__' is already defined
    

    The same error is thrown for the following:
    PROGRAM_NAME='master'
    #define __A_TOKEN__ 'A Token'
    #if_not_defined __A_TOKEN__
    	#define __A_TOKEN__ 'Same Token'
    #end_if
    

    I would dearly love to see this fixed!

    I even tried to put braces around it and it failed.
    #define __A_TOKEN__ 'A Token'
    #if_not_defined __A_TOKEN__
    	{
    	#define __A_TOKEN__ 'Same Token'
    	}
    #end_if
    

    That is annoying.
  • rfletcherrfletcher Posts: 217
    Wow, that's very odd since it is perfectly fine to do the following
    PROGRAM_NAME='include1'
    #if_not_defined token
    
    #define token true
    
    ...NetLinx Code...
    
    #end_if
    
    PROGRAM_NAME='include2'
    #include 'include1.axi'
    
    PROGRAM_NAME='main'
    #include 'include1.axi'
    #include 'include2.axi'
    

    On the surface this would appear to produce a situation that would look exactly like the one you presented, but the compiler must be doing something weird
  • jimmywjimmyw Posts: 112
    The mention of INCLUDE brings up a sore point for me. I would love to see IMPORT being used instead of INCLUDE, import being smarter about not including files twice automagicly,( Yes I love that word), objective C is great about that.

    I have predefined include files that contain specific purpose built functions, that only some systems need, but if there is an overlap, say 2 includes need the XML processing include, after copying over all files I have to comment out whichever one I include lower on the main page, whereas an import would ignore the second import of XmlTools.axi without any interaction needed.

    Jimmy
  • rfletcherrfletcher Posts: 217
    jimmyw wrote: »
    The mention of INCLUDE brings up a sore point for me. I would love to see IMPORT being used instead of INCLUDE, import being smarter about not including files twice automagicly,( Yes I love that word), objective C is great about that.

    I have predefined include files that contain specific purpose built functions, that only some systems need, but if there is an overlap, say 2 includes need the XML processing include, after copying over all files I have to comment out whichever one I include lower on the main page, whereas an import would ignore the second import of XmlTools.axi without any interaction needed.

    Jimmy

    You can get around this problem by wrapping the include file in an #if_not_defined statement.
    PROGRAM_NAME='XmlTools.axi'
    
    #if_not_defined XmlToolsDefined
    
    #define XmlToolsDefined true
    
    <Code Here>
    
    #end_if
    

    This keeps the code portion of the file from being included twice. Though it would be nice if NetLinx did it automatically :D
Sign In or Register to comment.