#include confusion

 

I use the #include statement in an MQ4 file to #include an mqh file. When I compile it, there is no error. I then go the the mqh file and put in an obvious error, but don't compile it. I then go back to the MQ4 file and compile it again and there is no error.

That tells me that the compiler doesn't use the mqh file to compile the MQ4 file, it uses the compiled file (ex4), otherwise my obvious error would cause an error.

But when I compiled the mqh file, I get warnings saying "function <some_function> is not references and will be removed from the exp(?) file"

So where does the compiler get the unreferenced functions to include in the compiled mq4 file? And what is an exp file?

 
FoxGuy:
I use the #include statement in an MQ4 file to #include an mqh file. When I compile it, there is no error. I then go the the mqh file and put in an obvious error, but don't compile it. I then go back to the MQ4 file and compile it again and there is no error.
Then you're doing something wrong. Are you pressing the save button before switching? Compiling also saves but includes aren't compiled.
 
WHRoeder:
Then you're doing something wrong. Are you pressing the save button before switching? Compiling also saves but includes aren't compiled.

I went and did it again to make sure that I didn't do something accidentally.

1. Compiled B.mqh (contains myFunction() in it) -- no error, warning myFunc is not referenced and will be removed from exp-file. (still don't know what an "exp-file" is).

2. Made sure that A.mqh uses myFunction() and has "#include <B.mqh>".

4. Compiled A.mqh -- no errors.

5. Typed "hi" in myFunction() in B.mqh with no semicolon (did not compile or save or anything else).

6. Compiled A.mqh -- no errors.

7. Compiled B.mqh -- error "hi" - variable not defined.

8. Compiled A.mqh -- error "hi" - variable not defined.

9. Took "hi" out of myFunction() in B.mqh.

10. Compiled B.mqh -- warning myFunc is not referenced and will be removed from exp-file.

11. Compiled A.mqh (that still used myFunction()) - no error.

Step 6 shows that the compiler does not use B.mqh to compile A.mqh. If it did it would produce the error as in step 8. It had to be using B.ex4 file to compile A.mqh.

But steps 1 & 10 show that myFunction() is being removed from the exp-file. It obviously wasn't removed from the ex4 file.

Reason: