Features of the mql5 language, subtleties and tricks - page 299

 
Andrei Iakovlev #:

seems like it's impossible to create such macro to deal with any amount of variables, like Print function does

Yes indeed, unlike C preprocessor, the MQL preprocessor does not support variadic macros that accept a variable number of arguments like #define PRINT(...).


Edit:
You can use workaround solutions like the previously posted TOSTR() to support multiple arguments to Print() function.

https://www.mql5.com/en/forum/393227/page298#comment_56270175
 
amrali #:
You can use workaround solutions like the previously posted TOSTR() to support multiple arguments to Print() function.

I already did that here: https://www.mql5.com/en/forum/393227/page298#comment_56271584

 
amrali #:
Yes, indeed, unlike the C preprocessor, the MQL preprocessor does not support variational macros that take a variable number of arguments, like #define PRINT(...).

h ttps:// gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html

Edit:
Workarounds, such as the previously published TOSTR(), can be used to support multiple Print() arguments.

https:// www.mql5.com/en/forum/393227/page298#comment_56270175

Offtopic, but want to correct. Highlighted:

Itis better to write "Added". It will be more correct in Russian.

Because "Edit" is not the right verb form to use here.

For general development ;)

 
Ok, thanks Artyom. Now I realized that eng->rus auto translation can sometimes modify the meaning.
 
amrali #:
Okay, thanks, Artyom. Now I realise that auto-translation eng->rus can sometimes change the meaning.

Yes. Nothing is perfect)

UPD: Here the meaning is not lost. It makes sense, but it looks "jaggy". Closer in meaning would be "Edited:"

 

Undocumented DEAL_TYPE: so compensation.

void OnStart()
{  
  const ulong Ticket = 786026654;
  
  if (HistoryDealSelect(Ticket))
    Print(EnumToString((ENUM_DEAL_TYPE)HistoryDealGetInteger(Ticket, DEAL_TYPE))); // ENUM_DEAL_TYPE::19
}
 
fxsaber #:

Undocumented DEAL_TYPE: so compensation.

Is it a type for draining the account to zero?

 

Some variable has a value of -1.

Which check will be executed faster to check this value: < 0 or == -1?

 
Andrei Iakovlev #:

Some variable has a value of -1.

Which check will be executed faster to check this value: < 0 or == -1?

I can suppose that <0, because it is one machine command, and ==-1 - comparison with a constant to be loaded. But it depends on the compiler.

Also, it will only appear in some way in a rather large loop.

 
JRandomTrader #:

I can assume that <0 is a single machine command, and ==-1 is a comparison with a constant to be loaded. But it depends on the compiler.

Also, it will only appear in some way in a rather large loop.

https://godbolt.org/

And how many clock cycles and what instruction it takes - dig it yourself, if you are interested)))))

IMHO, in practical terms, it is absolutely unimportant.

Compiler Explorer
Compiler Explorer
  • About the author
  • godbolt.org
Compiler Explorer is an interactive online compiler which shows the assembly output of compiled C++, Rust, Go (and many more) code.