Home AMX User Forum NetLinx Studio

Universal constants

I am looking to use a set of constants all of my .axi files in my system. I created a constants.axi that held all of my constant and included it into my other .axi files where the code will call them. When including those set of axi into my axs, I am receiving an error that symbol [defined_constant] is already defined. Any suggestions on how to create it?

Comments

  • ericmedleyericmedley Posts: 4,177
    arbelaezc wrote: »
    I am looking to use a set of constants all of my .axi files in my system. I created a constants.axi that held all of my constant and included it into my other .axi files where the code will call them. When including those set of axi into my axs, I am receiving an error that symbol [defined_constant] is already defined. Any suggestions on how to create it?

    More than likely you have a constant(s) declared in some other include or in the main file. Bret thing to do is just do a 'find' by whatever the variable name is. It also might be defined as a var or local or stack var.
  • the8thstthe8thst Posts: 470
    arbelaezc wrote: »
    I am looking to use a set of constants all of my .axi files in my system. I created a constants.axi that held all of my constant and included it into my other .axi files where the code will call them. When including those set of axi into my axs, I am receiving an error that symbol [defined_constant] is already defined. Any suggestions on how to create it?

    The include file with the constant declarations only needs to be included once, not in every include file.

    Make your declaration include the first one in your main program and it will populate all of the definitions into each include file that follows it.
  • jimmywjimmyw Posts: 112
    arbelaezc wrote: »
    included it into my other .axi files where the code will call them.

    You only need to include it once, preferably as the very first include in your main AXS master file.
  • AuserAuser Posts: 506
    arbelaezc wrote: »
    When including those set of axi into my axs, I am receiving an error that symbol [defined_constant] is already defined. Any suggestions on how to create it?

    Wrap the constant declarations in your .axi in preprocessor directives as follows:
    #IF_NOT_DEFINED    __CONSTANTS_AXI__
    #DEFINE            __CONSTANTS_AXI__
    
    DEFINE_CONSTANT
    // Include your constant definitions here
    
    #END_IF
    

    The code wrapped in the #IF_NOT_DEFINED block will only ever be included in the compilation once hence your compilation error shouldn't keep occurring. If it does, you must have an extraneous declaration of that constant somewhere else in your code.

    From memory the NetLinx compiler is fairly tolerant and will compile two declarations of the same constant with the same initialiser (like the following):
    DEFINE_CONSTANT
    A_CONSTANT = 1
    A_CONSTANT = 1
    

    But will throw the compiler error you mentioned if it encounters two declarations of the same constant with different initialisers (such as this):
    DEFINE_CONSTANT
    A_CONSTANT = 1
    A_CONSTANT = 2
    

    So I'm a little concerned that you may have two constants with the same name being defined with different values in your code.
  • rfletcherrfletcher Posts: 217
    I use the preprocessor directives on almost all my includes specifically so I can put the #include statement in every file so that studio will correctly highlight and auto-complete the contents of the include file.
  • viningvining Posts: 4,368
    rfletcher wrote: »
    I use the preprocessor directives on almost all my includes specifically so I can put the #include statement in every file so that studio will correctly highlight and auto-complete the contents of the include file.
    I also do this for module parameters with out initialization values since there's no need for them.
    MODULE_NAME='VAV_Oppo_DVD_Mod,Rev0'(DEV vDEVcomm,DEV dvDEV,INTEGER nInstance,CHAR cIP[],INTEGER nComType,INTEGER nDeBug)
    
    DEFINE_DEVICE   //#DEFINE DEFINE_MODULE_PARAMETERS
    
    //THIS JUST ALLOWS HIGHLIGHTING & AUTOCOMPLETE ITEMS PASSED IN THE HEADER
    #DEFINE DEFINE_MODULE_PARAMETERS
    #IF_NOT_DEFINED DEFINE_MODULE_PARAMETERS
    vDEVcomm 		
    dvDEV 	        	
    #END_IF
    
    DEFINE_VARIABLE //MODULE HEADER PARAMETERS 
    
    //THIS JUST ALLOWS HIGHLIGHTING & AUTOCOMPLETE ITEMS PASSED IN THE HEADER
    #DEFINE DEFINE_MODULE_PARAMETERS
    #IF_NOT_DEFINED DEFINE_MODULE_PARAMETERS
    nInstance
    cIP 
    nDeBug 
    nComType        	
    #END_IF
    
  • jimmywjimmyw Posts: 112
    vining wrote: »
    I also do this for module parameters with out initialization values since there's no need for them.

    Well, I'll be damned, I am going to have to start doing that to make my life easier.

    Jimmy
  • arbelaezcarbelaezc Posts: 12
    So where exactly do I put the include in? This is how I have it:
    PROGRAM_NAME='West_Source'
    
    DEFINE_CONSTANT //-----------------------------------------
    #INCLUDE 'Constants.axi'
    
    DEFINE_TYPE //---------------------------------------------
    
    
    DEFINE_VARIABLE //-----------------------------------------
    
    
    DEFINE_LATCHING //-----------------------------------------
    
    
    DEFINE_MUTUALLY_EXCLUSIVE //-------------------------------
    #include 'RM205.axi'
    

    I am getting and internal compiler error. (C10580)

    Here is my Constants.axi code:
    PROGRAM_NAME='Constants'
    
    DEFINE_CONSTANT //--------------------------------------------------------
    #DEFINE MY_CONSTANTS
    //constants go here
    
    

    Here is my RM205.axi:
    PROGRAM_NAME='RM205'
    
    DEFINE_CONSTANT //--------------------------------------------------------
    #IF_NOT_DEFINED MY_CONSTANTS
    

    what am I doing wrong?
  • arbelaezcarbelaezc Posts: 12
    Auser wrote: »
    Wrap the constant declarations in your .axi in preprocessor directives as follows:
    #IF_NOT_DEFINED    __CONSTANTS_AXI__
    #DEFINE            __CONSTANTS_AXI__
    
    DEFINE_CONSTANT
    // Include your constant definitions here
    
    #END_IF
    


    Do I include that in all my AXIs?
  • AuserAuser Posts: 506
    arbelaezc wrote: »
    Do I include that in all my AXIs?

    Only in your constants.axi file.

    Add the #IF_NOT_DEFINED/#DEFINE lines to the top of the file and the #END_IF directive to the bottom of the file like this:
    #IF_NOT_DEFINED    __CONSTANTS_AXI__
    #DEFINE            __CONSTANTS_AXI__
    
    DEFINE_CONSTANT
    // Include your constant definitions here
    CONSTANT_A = 1
    CONSTANT_B = 2
    [etc...]
    
    #END_IF
    

    These pre-processor directives ensure that the block of code they enclose will only be included in the compilation once, no matter how many times you #include the file that code resides in in other source files.
  • Auser has the right idea here. Consider this to be me hitting the Like button. :)
  • Auser wrote: »
    Only in your constants.axi file.

    Add the #IF_NOT_DEFINED/#DEFINE lines to the top of the file and the #END_IF directive to the bottom of the file like this:
    #IF_NOT_DEFINED    __CONSTANTS_AXI__
    #DEFINE            __CONSTANTS_AXI__
    
    DEFINE_CONSTANT
    // Include your constant definitions here
    CONSTANT_A = 1
    CONSTANT_B = 2
    [etc...]
    
    #END_IF
    

    These pre-processor directives ensure that the block of code they enclose will only be included in the compilation once, no matter how many times you #include the file that code resides in in other source files.

    I #include my Constants.axi file in all the .axi files including the master .axs and am still getting and error code.

    ERROR: (0): C10580: Internal Error: Major system error occurred during code generation

    I still must be doing something wrong. I'll show you what I have.

    Master:
    PROGRAM_NAME='West_Source'
    
    DEFINE_DEVICE //-------------------------------------------
    //devices
    
    DEFINE_CONSTANT //-----------------------------------------
    #INCLUDE 'Constants.axi'
    
    DEFINE_TYPE //---------------------------------------------
    
    
    DEFINE_VARIABLE //-----------------------------------------
    
    
    DEFINE_LATCHING //-----------------------------------------
    
    
    DEFINE_MUTUALLY_EXCLUSIVE //-------------------------------
    #INCLUDE 'RM205.axi'
    #INCLUDE 'RM206.axi'
    #INCLUDE 'RM209A.axi'
    #INCLUDE 'RM209.axi'
    #INCLUDE 'RM213.axi'
    #INCLUDE 'RM214.axi'
    
    //rest of program
    

    Room code (all are the same):
    PROGRAM_NAME='RM205'
    
    DEFINE_DEVICE //----------------------------------------------------------
    //devices
    
    DEFINE_CONSTANT //--------------------------------------------------------
    #INCLUDE 'Constants.axi'
    //rest of code
    

    Constants.axi:
    PROGRAM_NAME='Constants'
    
    #IF_NOT_DEFINED MY_CONSTANTS
    #DEFINE MY_CONSTANTS
    DEFINE_CONSTANT
    //constants definitions
    #END_IF
    
  • rfletcherrfletcher Posts: 217
    arbelaezc wrote: »
    I #include my Constants.axi file in all the .axi files including the master .axs and am still getting and error code.

    ERROR: (0): C10580: Internal Error: Major system error occurred during code generation

    That has to be in the running for the most unhelpful error message ever.

    Best way I know of to hunt for this error is to comment out every include statement in your program and add them back one at a time until you see the error so you at least have a vague clue where to start looking for the thing.
  • Joe HebertJoe Hebert Posts: 2,159
    arbelaezc wrote: »
    ERROR: (0): C10580: Internal Error: Major system error occurred during code generation

    I'm sure there are other reasons but I know that two functions with the same name will cause that error.
  • Joe Hebert wrote: »
    I'm sure there are other reasons but I know that two functions with the same name will cause that error.

    Yup, think that's the only time(s) I've seen that error.
  • Joe Hebert wrote: »
    I'm sure there are other reasons but I know that two functions with the same name will cause that error.

    Thanks Joe! I did have the a function whose name I never changed. All the code compiled. Now to test. Thanks again everyone!
  • the8thstthe8thst Posts: 470
    Joe Hebert wrote: »
    I'm sure there are other reasons but I know that two functions with the same name will cause that error.

    That is what I was going to suggest as well. Two like named functions = major error.
Sign In or Register to comment.