Jump to content

#include-once... sort of


 Share

Recommended Posts

Let's say I have three libraries. Libraries 1 and 2 use functions from library 3. My main script uses functions from all three libraries. Right now, I have #include-once as the first line of all three libraries. In my main script, I #include all three libraries making sure that library 3 is first so the compiler won't complain. Life is good, the birds sing, the code works. :lmao:

The problem is, when I've got all 4 files loaded, I have to go to my main script to see if I've got any syntax errors in the libraries. I can't be in library 1 and syntax check because it'll complain that I'm using undefined functions (that are defined in library 3).

What I would like to do in each of the libraries is put #include-once on the first line and then below that use #include to include the dependent library. So library 1 and 2 would #include library 3. However, you can't do that because when you try to compile the main script (which has all 3 libraries included) the compiler will tell you that you've got duplicate function declarations. I was hoping that AutoIt would keep track of the #include-once statements so that you could nest them.

I was just curious if I am doing something wrong (or over complicating again). Additionally, has there been any thought to changing the compiler so that you could nest the #include-once statements as in the scenario above?

Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

No example means no help. Create a small reproduction scenario, zip it up and attach it.

Edit: And in doing that, you'll probably find your mistake. I just tried what I think you described and as expected there were no issues.

Edited by Valik
Link to comment
Share on other sites

Here you go. I have set these up with the #include-once and #include statements as I thought they should work so that I could compile each library without having to go to the main script to check for syntax errors. I can't seem to make the main script compile without telling me that I've got duplicate functions. Same thing with the first library. Like you said, I've probably just got something messed up, but for the life of me I can't spot the problem.

Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

I think I see what the problem is. It appears that having spaces in the #include <...> statement breaks #include-once. I was playing with the example that I posted and when I remove the spaces after the file name and before the ">" in the #include statement, everything works as you would expect. Bug?

Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

No problems with your setup for me. That's how I thought you were using it and it works. All scripts run fine except Main.au3 which obvious has a recursion problem. But it does run until it hits the recursion limit. I get no duplicate function errors. Same goes for compiling. They all compile cleanly and run cleanly other than the recursion error.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...