Function that returns 2 results? - page 3

 
gordon:
Here is a simplified explanation -> https://www.mql5.com/en/forum/117210. Arrays are always passed by reference in MQL4.

Yes, thanks. But like I asked does that implies that on other language it isn't? If it were the only way to brought it about using MQ/MT4 or other language construct then I assume they wouldn't have to trouble themselves stating it.

I guess I'm asking the 'technical details' as you said on that post. Just out of curiosity not necessity.

As to the syntax, THE MQL5 language for programming trading strategies is very much similar to the C++ programming language, except for some features:

  • no address arithmetic;
  • no goto operator;
  • an anonymous enumeration can't be declared;
  • constructors of classes and structures can't have parameters;
  • no multiple inheritance.

Like this, I can imply that on C++ the opposite will be true... Thanks anyway, Gordon.

 
Matutin:

I'm sorry, but it's not a "technical" response :) Could you say why it is better to pass variable by reference instead of global variable ?

Many reasons which I prefer not to repeat, instead I'll refer u to here -> https://en.wikipedia.org/wiki/Global_variable and here -> http://www.c2.com/cgi/wiki?GlobalVariablesAreBad (you can Google for more... It's a widely accepted concept and there's much info on the net).

 
cameofx:

[...] does that implies that on other language it isn't? [...]

It doesn't imply anything, but specifically in both C and C++ arrays are passed by reference as well (technically a pointer to the array's first element is passed, that pointer is passed by value).
 
gordon:

Many reasons which I prefer not to repeat, instead I'll refer u to here -> https://en.wikipedia.org/wiki/Global_variable and here -> https://www.mql5.com/go?link=http://www.c2.com/cgi/wiki?GlobalVariablesAreBad (you can Google for more... It's a widely accepted concept and there's much info on the net).


Very interesting ! Unfortunately, EA need parameters, and sometime a lot, so we can't avoid them and have to take care for all reasons mentionned in https://www.mql5.com/go?link=http://www.c2.com/cgi/wiki?GlobalVariablesAreBad

I'm using naming rules for GlobalVariable : Much easier to manage and avoid some bugs.

Thanks Gordon.

 
Matutin:

Very interesting ! Unfortunately, EA need parameters, and sometime a lot, so we can't avoid them [...]

Externs are indeed unavoidable. Although they are global in scope, they are not the same as global variables (not to be confused with GV's); specifically - it is not recommended to change their value via code, hence they should not be used to pass info between functions anyway (see here -> https://www.mql5.com/en/forum/123535).


I'm using naming rules for GlobalVariable : Much easier to manage and avoid some bugs.

This discussion is about variables defined on global scope (declared outside the special function start(), init(), deinit()) and not about GV's... Don't mix the two.
 

Just curous: are there ANY programming languages that have functions that return multiple results?

 

maybe you could kinda trick a function into returning two values by combining them in a way that you can uncombine them again in the calling function

something like this

a = 10;

b = 20;

a = a*1000

c = a+b // 10020

return(c);

then in the calling function

b = c%1000 // 20

a = c-b/1000 // 10

 
SDC:

maybe you could kinda trick a function into returning two values by combining them in a way that you can uncombine them again in the calling function

something like this

[...]
Maybe not.
 

why not ?

 
SDC:

why not ?

Why solve a problem that doesn't exist? Why reinvent the wheel? Why make up unclear code which would only work in limited cases?
Reason: