Vladislav Boyko #: If this is not casting NULL to int, then what is it called?
Your example is valid, but it is not the same situation.
In your code the target type is explicitly int, so the compiler interprets NULL as zero and assigns it without issue.
In Dominik's template example the type T is deduced from the argument, and since NULL is of type void*, the compiler cannot infer T as int. That is why it fails.
So your case shows implicit conversion once the type is fixed, while Dominik's case fails because of type deduction rules. They are different mechanisms and cannot be grouped together.
False bug report. The error is due to poor programming by the OP. The documentation itself specifies and clarifies this.
It is stated here in the documentation:
"The predefined constant variable NULL is of the void type. It can be assigned to variables of any other fundamental types without conversion. The comparison of fundamental type variables with the NULL value is allowed." (See section: Void Type and NULL Constant, MQL5 Reference)
But that only covers assignment and comparison, not its use inside arithmetic expressions or template type deduction.
In expressions or templated functions, the compiler requires a concrete type. Since NULL is of type void, it cannot be deduced as int, double, or any other numeric type, which is why the compilation error occurs.
Example only to illustrate that NULL is valid syntactically for pointer types, not for numeric use:
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
On Friday, October 3, 2025, an updated version of the MetaTrader 5 desktop platform will be released.
Found a casting bug:
Reference is documentation:
https://www.mql5.com/en/docs/basis/types/casting
Failing code example:
Compiler log:
NULL is not numeric. You can't and will never be able to cast NULL to an integer in MQL5.
You can't and will never be able to cast NULL to an integer in MQL5.
If this is not casting NULL to int, then what is it called?
If this is not casting NULL to int, then what is it called?
Exactly. - And, by documentation, the function-like casting is very well supported, but failing my example case.
Failing code example:
I made your example work by adding a couple of extra parentheses.
I made your example work by adding a couple of extra parentheses.
"The predefined constant variable NULL is of the void type. It can be assigned to variables of any other fundamental types without conversion. The comparison of fundamental type variables with the NULL value is allowed." (See section: Void Type and NULL Constant, MQL5 Reference)
But that only covers assignment and comparison, not its use inside arithmetic expressions or template type deduction.
In expressions or templated functions, the compiler requires a concrete type. Since NULL is of type void, it cannot be deduced as int, double, or any other numeric type, which is why the compilation error occurs.
Example only to illustrate that NULL is valid syntactically for pointer types, not for numeric use: