Home AMX User Forum AMX Technical Discussion

Include Files - Is there a max limit?

Hi there,

Is there a maximum limit on include files? I have a main with all my include files listed and I have different includes for all the source devices, relays and touch panel page flips. I use these to keep everything organised mainly but Im experiencing some strangeness where some of the last includes listed in the main arent carrying
out their input actions...

Is there a maximum amount allowed? I always believed that the main compiles the includes as if they are part
of the main?.?.?

Comments

  • viningvining Posts: 4,368
    mkleynhans wrote: »
    Hi there,

    Is there a maximum limit on include files? I have a main with all my include files listed and I have different includes for all the source devices, relays and touch panel page flips. I use these to keep everything organised mainly but Im experiencing some strangeness where some of the last includes listed in the main arent carrying
    out their input actions...

    Is there a maximum amount allowed? I always believed that the main compiles the includes as if they are part
    of the main?.?.?

    If you have the memory available you shouldn't have any problems AFAIK.

    When that happens to me there's usually a semi-colon out of place, after a function definition
    DEFINE_FUNCTION fnSomeFunction();
    
    or even after the includes themselves,
    INCLUDE 'xxxxx'; 
    #INCLUDE'xxxxx';
    
    in both case I believe the the semi-colon terminates the call so nothing is included in the case of includes and the functions don't get pulled in either.

    The includes are all pulled in to the main but in the order they are received so something in a later include can't reference something in an earlier include, except for functions which seem to be treated differently than variable and constants.

    It would be nice if the compiler made at least 2 passes, build the file on the first pass, sorting and organizing and then the 2nd pass to compile then you wouldn't have these referncing issues.
  • Thanks Vining!
  • AuserAuser Posts: 506
    mkleynhans wrote: »
    I use these to keep everything organised mainly but Im experiencing some strangeness where some of the last includes listed in the main arent carrying
    out their input actions...

    Are you using any #if_defined/#if_not_defined preprocessor directives?

    The only time I've seen issues with code in include files apparently not functioning is when one of these directives hasn't been terminated correctly with a #end_if causing the precompiler to exclude all code post that point.

    To illustrate another case where this could happen, consider the following:
    // ASourceFile.axs
    #include 'LibStuff.axi'
    #include 'LibStuff.axi'
    #include 'LibNonsense.axi'
    #warn 'Preprocessor has reached the end of the source files...'
    
    // LibStuff.axi
    #if_not_defined __LIB_STUFF__
      #define __LIB_STUFF__
      // Source goes here
    
      #warn 'LibStuff.axi has been included...'
    #end_if
    
    // LibNonsense.axi
    #if_not_defined __LIB_NONSENSE__
      #define __LIB_NONSENSE__
      // Source goes here
    
      #warn 'LibNonsense.axi has been included...'
    #end_if
    

    Note that LibStuff.axi will only be included in the compilation once, even though it is #included twice. More importantly, if the first line of LibNonsense.axi was actually #if_not_defined __LIB_STUFF__, it would never be included in the compilation because __LIB_STUFF__ was previously declared as a token in LibStuff.axi. This has caught me out when I've copied a .axi and created a new file from it and haven't been thorough enough stripping out the previous source code.

    Placing a statement like #warn 'SomeInclude.axi has been included...' in each include file will tell you quickly which include files are being included.

    Placing a statement like #warn 'Preprocessor has reached the end of the source files...' at the very bottom of the main source file will quickly tell you whether it is getting to the end of the master source file or whether the precompiler isn't including all of it.
Sign In or Register to comment.