The difference between extern and input - page 4

 
Igor Makanu:

How about declaring a variable of enum type?

implicit enum conversion tst1.mq5 24 17


you can also check EnumToString()...


I think the type without declared variables was just thrown out of the compilation as not used

I mean, you can accidentally declare a variable with the same name as in the enum already in use and then have a very long and painful time searching for where and where I shot myself in the knee

 
Maksim Neimerik:
So what is the verdict, gentlemen? If I write an .mq5 program with .mqh (#include), I can safely write extern and not be afraid of unexpected consequences (as I did in mql4), or using input ?

In MT5 use input to declare external variables. Extern in MT5 has a different purpose.

 
Dmitry Fedoseev:

In MT5 use input to declare external variables. Extern in MT5 has a different purpose.

Why cannot you use extern in MT5? - I compiled my example in MT5, I do not see a fundamental difference

 
Igor Makanu:

Why can't extern be used in MT5? - I compiled my example in MT5, I don't see any fundamental difference

Because people out of habit from the old MQL4 are trying to use extern for input parameters.

And in the new MQL4 and MQL5, input is used together with #property strict, and extern is used for other purposes.

That's why it was said not to use extern.

 
Artyom Trishkin:

Because people out of habit from ancient MQL4 try to use extern for input parameters.

And in new MQL4 and MQL5, input is used together with #property strict, and extern is used for other purposes.

That's why I told you not to use extern.

So everyone is trying to write a lot of bukuffs and the result is that they should NOT use ONLY in MQL5 and should NOT use anywhere else))))


ok, here comes the big argument, imho - if you see extern in an old code, replace it with input and fix all the warnings, and may the power of MQL be with you !!!!

 
Igor Makanu:

You see, everyone tries to write a lot of bukuffs and end up with NOT using ONLY in MT5 or NOT using anywhere at all ))))


Ok, here comes the big argument, imho - if you see extern in an old code, replace it with input and correct all warnings, and may the power of MQL be with you !!!!

I don't understand much of what's written here.

But I meant not to use extern in MQL5 and MQL4 with #property strict to declare external parameters of programs, but to use for the purpose described (vaguely) in the help.

 

I've been thinking, just a thought... In MQL5, isn't working with iCustom() much more problematic than in MQL4 (or generally with indicator calls in MQL4)? Is it so? If yes, then I will continue.

I've just started to learn MQL5 a little...

I will probably start a new topic.
 
Maksim Neimerik:
I'm just thinking... In MQL5 it's much more difficult to work with iCustom() than in MQL4 (or generally with indicators calling in MQL4), isn't it? Is it so? If so, I will continue.

not more problematic, it's just that in MQL5 you have to work with iCustom() in two steps:

1. get the indicator handle

2. request the values of indicator buffers through CopyBuffer()


in MQL4 - iCustom() works as a function call with parameters - you call it, receive it

in MQL5 it works the same way - the developers purposely reduced the functionality of built-in functions and made access to timeseries inconvenient - they just recently added iClose(), iHigh() to MQL5, before they needed to copy the data into an array as with CopyBuffer()

in general, MT5 has more writing than MT4

 
Igor Makanu:

not more problematic, it's just that in MQL5 you have to work with iCustom() in two steps:

1. get the indicator handle

2. request the values of indicator buffers through CopyBuffer()


in MQL4 - iCustom() works as a function call with parameters - you call it, receive it

in MQL5 it works the same way - the developers purposely reduced the functionality of built-in functions and made access to timeseries inconvenient - they just recently added iClose(), iHigh() to MQL5, before they needed to copy the data into an array as with CopyBuffer()

in general, MT5 has more writing than MT4

https://www.mql5.com/ru/forum/316800

MQL4 & MQL5
MQL4 & MQL5
  • 2019.06.29
  • www.mql5.com
Я тут вот что думаю, просто мысли... В MQL5 ведь намного проблемнее работа с iCustom() чем в MQL4 (да и вообще с вызовом индикаторов в советнике...
 

Unfortunately, the implementation of extern variables in MQL5 is not finalized, and that's why I don't recommend using it - it might cause problems. I mean the lack of control over the mandatoryone-time initialization of these variables.

For example, you may write it in such a way:

extern int a=1;
extern int a=2;

and there will be no error. Imagine that these initializations are performed in different plugins. Then the final result will depend on the order in which these files are included.

Or we can write it like this (executable file):

extern int a;

void OnStart() { Print(a); }

here we haven't initialized the extern-variable at all, but there's no error either.

Accordingly, there's no control over whether or not the same variables are defined in other files. You can accidentally change its name, but the program will compile as if nothing had happened, although in other files we have a variable with a different name.

All in all, it does not fit anywhere. That's why it's better to use functions instead of extern-variables. They are guaranteed to have only one definition, no more and no less.

Reason: