Difference between "extern" variable type in mql4 vs mql5

 
As in topic what is the difference between them? Documentation in mql5 seems to be avoiding proper definition and examples for extern type.
 
Majkel:
As in topic what is the difference between them? Documentation in mql5 seems to be avoiding proper definition and examples for extern type.
Since recently, in MQL5 the keyword extern has the same functionality as in C/C++.

In MQL4 extern defines a variable to be a mutable input parameter. Contrary to input, which has the properties static and const, thus cannot be changed, an extern declared variable can be assigned, though it being an input variable.

The "modern" version of the keyword extern, as in C/C++ is a declaration type that refers to usage with multiple header files, all using the same variable name. This means, you declare in multiple header files the same variable, but with the keyword extern. In your main program you declare this variable without the keyword extern. Now all your code will actually reference this one and single non-extern declared variable.

This makes it somewhat "easier" to have common memory globals declared, and used in multiple header files.

I personally am no fan of such, but if you need it, you can do it this way.
 
Thank You! If I wanted to use the same functionality as from mql4 "extern" offers but in mql5 what type should i call?
 
Majkel #:
Thank You! If I wanted to use the same functionality as from mql4 "extern" offers but in mql5 what type should i call?

as per the documentation you should use   input

but note the input value is static

https://www.mql5.com/en/docs/basis/variables/inputvariables
Documentation on MQL5: Language Basics / Variables / Input Variables
Documentation on MQL5: Language Basics / Variables / Input Variables
  • www.mql5.com
Input Variables - Variables - Language Basics - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Dominik Egert #:
which has the properties static and const
Paul Anscombe #:
but note the input value is static

What do you mean by "static"?

Are you saying that variable 'a' is static?

input int a = 1;

If so, are the variables 'b' and 'c' doubly static?😄

static input int b = 1;
sinput int       c = 1;

 

Personally, I don't program in C++ and I don't understand how you can say that a global variable is static. I understand static local variables, static members and methods for a class/struct. I also understand what sinput means. But I don't understand how you can characterize a global variable (not a member of a class/struct) as static. What does this mean?

[EDIT]

What is the difference between x and y?

static int x = 1;
int        y = 1;

void OnStart()
  {
   Print(++x*++y);
  }
 
Majkel #:
Thank You! If I wanted to use the same functionality as from mql4 "extern" offers but in mql5 what type should i call?
There is no equivalent in MQL5 to MQL4s extern.
 
Vladislav Boyko #:
Personally, I don't program in C++ and I don't understand how you can say that a global variable is static. I understand static local variables, static members and methods for a class/struct. I also understand what sinput means. But I don't understand how you can characterize a global variable (not a member of a class/struct) as static. What does this mean?
All global variables are static, that's by definition. Actually, global and static memory refer to the same memory region.

A locally declared static variable is in the same memory space as global variables.

So global variables are considered to be of type static, though most people use it implicit.
 
Vladislav Boyko #:

Personally, I don't program in C++ and I don't understand how you can say that a global variable is static. I understand static local variables, static members and methods for a class/struct. I also understand what sinput means. But I don't understand how you can characterize a global variable (not a member of a class/struct) as static. What does this mean?

[EDIT]

What is the difference between x and y?

Actually, there is no difference. See my previous post.
 
Dominik Egert #:
Actually, there is no difference. See my previous post.

I got it, thank you

 
I think better way to say that would be that they are stored staticly in memory, not accessed staticly from program. Thank You all for the discussion and answers, sad to hear there is no "extern" equivalent in mql5 :( Isn't it a downgrade? Why mql4 is used more often than mql5, if there is no possibility to download mt4 directly from mq?