The difference between extern and input - page 2

 
Artyom Trishkin:

Everything is clear about input. The thing about extern - there, as it seems to me, you can first declare variables with the same type and identifier in different files to be attached to the project, and then it turns out that you can't declare them that way. This is certainly a three-storey impressionism...

The meaning of extern is that if the main (main) file has some variable and another file is attached to this file. And in this attached file we need to use the variable declared in the main file, then in the attached file we declare it as extern. As a result, the linked file can be compiled and when the main file is compiled,the variable declaration in the linked file is ignored.

 
Alexey Viktorov:

I don't know. For me, all the documentation is self-explanatory. If there are difficulties somewhere, they disappear after some experimentation.

But if I'm not familiar with bitwise operations, I can read any article you want... I won't understand a word of it. Just like I couldn't understand anything about flags and flag sets until Artem explained them to me in a voice.

It's understandable if you require values from it, but how it all works before and after - darkest darkness

 
Fast235:

it is understandable if value is demanded of it, but how it all works before and after is murky, the darkest murk

Who is she?

 
Alexey Viktorov:

Who is she?

the essence of the job

 
Alena Lysenkova:

there is:
1) extern works only in mql4.
2) comments after input will be displayed in the input parameters instead of the input variable name
input int ma_period = 20;
- it will say "ma_period".
input int ma_period = 20; // MA period
- it will be written "MA period".
to be exactly like that in mql4, the strict compilation mode is needed #property strict.
This trick is absent with extern.
3) Extern variables can be changed in code like any global variables, input cannot.

Initially, there was only mql4 and extern, no input was present, neither was OOP in mql4.
Then mql5 was created and input was immediately included because mql5 in general was oriented exactly at OOP.
About 2-3 years ago, mql4 was upgraded with many features from mql5, including input.

What terminal are you writing about?

In MT5, if you declare an external variable as extern in the indicator, the indicator may not be able to be called via iCustom().

 
Dmitry Fedoseev:

What terminal are you writing about?

In MT5, if you declare an external variable as extern in an indicator, the indicator may not be able to be called through iCustom().

I'm not reproaching now, but you write "it may fail"... it turns out it may or may not work! I mean, it's hard for me as a self-taught person without special education to understand such uncertainty...

 
Alena Lysenkova:

there are:
1) extern only works in mql4.
2) comments after input will appear in input parameters instead of the input variable name
input int ma_period = 20;
- it will say "ma_period".
input int ma_period = 20; // MA period
- it will be written "MA period".
to be exactly like that in mql4, the strict compilation mode is needed #property strict.
This trick is absent with extern.
3) Extern variables can be changed in code like any global variables, input cannot.

Initially, there was only mql4 and extern, no input was present, neither was OOP in mql4.
Then mql5 was created and input was immediately included because mql5 in general was oriented exactly at OOP.
About 2-3 years ago, mql4 was upgraded with many features from mql5, including input.

extern works in both cases. So does input in MQL5 and MQL4. Their purpose is different, and it is written in the help.

Why direct a person straight away to a misconception about the purpose of input and extern variables?

 
Dmitry Fedoseev:

The meaning of extern is that if the main (main) file has some variable and another file is attached to this file. And in this attached file we need to use the variable declared in the main file, then in the attached file we declare it as extern. As a result, the linked file can be compiled, but when you compile the main file, the variable declaration in the linked file is ignored.

I also thought that this modifier works like in C++, i.e. it's declared in the include filehttps://www.mql5.com/ru/forum/160683/page867#comment_11927748

Checked it doesn't work as it should in C++


tstextern library file

//+------------------------------------------------------------------+
//| My function                                                      |
//+------------------------------------------------------------------+
extern int koef=1 ;
 int MyCalculator(int value,int value2) export
   {
    return((value+value2)*koef);
   }
//+------------------------------------------------------------------+

script file:

#import "tstextern.ex5"
int MyCalculator(int value,int value2);
#import

extern int koef;

void OnStart()
  {
      koef = 666;
      int res = MyCalculator(100,200);
      Print("result = ",res);
   
  }
//+------------------------------------------------------------------+

any manipulation of thekoef variable doesnothing, it is still in the local scope (inside each file)


Artyom Trishkin:

Their purpose is different and it is written in the help.

The difference is in the access control:

input - it can only be read, writing is prohibited.

extern - it can be read and written, and after reinitialization of MQL-program this value will be restored to the value specified in external settings

Любые вопросы новичков по MQL4 и MQL5, помощь и обсуждение по алгоритмам и кодам
Любые вопросы новичков по MQL4 и MQL5, помощь и обсуждение по алгоритмам и кодам
  • 2019.06.02
  • www.mql5.com
В этой ветке я хочу начать свою помощь тем, кто действительно хочет разобраться и научиться программированию на новом MQL4 и желает легко перейти н...
 
Maksim Neimerik:

I'm not being negative now, but you write "it might not work"... it might not work, but it might work! I mean, it's hard for me as a self-taught person without special education to understand such uncertainty...

I mean, I haven't checked right now. And it's dangerous to say what was once there, because things change so often. Maybe it was a temporary glitch.

 
Igor Makanu:

also thought that this modifier works like in C++, i.e. it is declared in the plugin filehttps://www.mql5.com/ru/forum/160683/page867#comment_11927748

it doesn't work as it should in C++


tstextern library file

script file:

any manipulation of thekoef variabledoes nothing, it's still in the local scope (inside each file)

Well, you have a library. Of course, there will be different variables. I mean the connection of mqh via include.

Reason: