Since when the external variables do not work? - page 2

 
Extern Variables

ExternVariables

The extern keyword is used for declaring variable with global lifetime. These variables exist from the start of the program and memory for them is allocated and initialized immediately after the start of the program.

You can create programs that consist of multiple source files; in this case a directive to the preprocessor #include is used. Variables declared as an externwith the same type and identifier can exist in different source files of one project.

When compiling the whole project, all the externvariables with the same type and an identifier are associated with one part of memory of the global variable pool. Externvariables are useful for separate compilation of source files. Extern variables can be initialized, but only once - existence of several initialized externvariables of the same type and with the same identifier is prohibited.

 
The extern keyword, which is preceded in front of a variable declaration in the MQL5 language, means that this variable is global and variables declared as extern with the same type and the same identifier can exist in several source files of the same project. You can create programs made from multiple source files by using #include preprocessor directives. The extern variables can be initialized, but only once - the existence of several external variables initialized of the same type and with the same identifier is prohibited. In case of misuse of an extern variable, one of these two errors below will appear:

• “external variable initialization is not allowed”
• “unexpected token”
 

I'm having the same problem...

I have a huge library, it always worked fine. Now I'm having issues about it


I'm not sure when this stopped working because I do not update it very often...

Any workaround or clue of what is happening?

 
Romeu Bertho #:

I'm having the same problem...

I have a huge library, it always worked fine. Now I'm having issues about it


I'm not sure when this stopped working because I do not update it very often...

Any workaround or clue of what is happening?

It's a recent change, still in progress.

extern declared variables should not be initialized. As it's clear stated in the error message.

You should have 1 time :

double Volume = 0;       // Definition, can be (must be) initialized

Then as much repetition in include files :

extern double Volume;    // Declaration, not definition, can't be initialized
 

Sorry to drag this one back up again. To be clear, my best option when I want to declare an input variable that can be modified when the code runs is to pass the value of the initialized variable onto another variable?

eg

input double  PercentInput = 1;
double Percent = PercentInput;

Or is there a better way to skin this cat?

 
rrsch #: To be clear, my best option when I want to declare an input variable that can be modified when the code runs is to pass the value of the initialized variable onto another variable?
Yes, that is the correct way to do it!
 
Romeu Bertho #:

I'm having the same problem...

I have a huge library, it always worked fine. Now I'm having issues about it


I'm not sure when this stopped working because I do not update it very often...

Any workaround or clue of what is happening?

extern double Volume=0; 
// would work in MQL4

input double Volume=0;
// this will work in MT5/MQL5
Reason: