Pre-processor directive bug
Auser
Posts: 506
This illustrates one of the bugs with the NetLinx compiler pre-processor which I find very frustrating.
Consider this program:
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:
Although the second #define statement should never be reached, the compiler fails with the error message:
The same error is thrown for the following:
I would dearly love to see this fixed!
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!
0
Comments
I even tried to put braces around it and it failed.
That is annoying.
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
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.
This keeps the code portion of the file from being included twice. Though it would be nice if NetLinx did it automatically