Understanding template function and NULL-Macro

 

Hello everyone,

I am stumbling accross following code for some reason I cannot comprehend why this is behaving as it is.

The code does not compile. But I would expect a different behaviour here, as somehow the compiler inconsistently applies the variable types.

I would expect the templated type to resolve consistently, also to the NULL macro, but it doesnt. 

My question is, how to work around this, and/or is this an issue with the compiler. 


I would expect to see 4 warnings and no errors. - Maybe I am wrong about that, but why?


//+------------------------------------------------------------------+
//|                                                   Playground.mq5 |
//|             Copyright 2020, Freie Netze UG (haftunbgsbeschränkt) |
//|                                      https://www.freie-netze.de/ |
//+------------------------------------------------------------------+




//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
    const double    d_init_val  = NULL;
    const uint      u_init_val  = NULL;
    double  d_test_arr[];
    uint    u_test_arr[];
    
    const int attempt_A = ArrayInitialize(d_test_arr, 0);
    const int attempt_B = ArrayInitialize(d_test_arr, NULL);
    const int attempt_C = ArrayInitialize(d_test_arr, d_init_val);
    const int attempt_D = ArrayInitialize(d_test_arr, u_init_val);
    const int attempt_E = ArrayInitialize(d_test_arr, 0.0);

    const int attempt_F = ArrayInitialize(u_test_arr, 0);
    const int attempt_G = ArrayInitialize(u_test_arr, NULL);
    const int attempt_H = ArrayInitialize(u_test_arr, u_init_val);
    const int attempt_I = ArrayInitialize(u_test_arr, d_init_val);
    const int attempt_J = ArrayInitialize(u_test_arr, 0.0);

    // Return
    return(INIT_SUCCEEDED);
}


//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{

    // Return
    return;
}


//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{

    // Return
    return;   
}


//+------------------------------------------------------------------+
//| Testing template function                                        |
//+------------------------------------------------------------------+
template <typename T>
int ArrayInitialize(T& arr_in[], T value)
{

    // Call API function
    ::ArrayInitialize(arr_in, value);

    return(::ArraySize(arr_in));
}