Possible Preprocessor Bug - page 2

 
Dominik Christian Egert #:
Understood. I will try to break it down and see.

My assumption it behaves like a C/C++ compiler is this page from the docs.

Especially paragraph 2.



The fact that the code works on VC++ and g++ and produces expected results, has let me assume, it is a bug.

As said, I will try to break it down even more. Although it is already down to one line and a comparison with a different compiler.

I understand, the effort is to much to track all the code provided.

Most of it is for giving all details. Because that's what usually is asked. All relevant code.

I will do my best to narrow it down.


Good. I have brought it to a MQ developer attention nonetheless.
 
Alain Verleyen #:
Good. I bring it to a MQ developer attention nonetheless.


Would be nice if you give me the possibility to break it down, if I can do so.

 
Alain Verleyen #:
Good. I have brought it to a MQ developer attention nonetheless.


That was fast.... I am no magician...
 
Dominik Christian Egert #:


Would be nice if you give me the possibility to break it down, if I can do so.

No worries.
 
Alain Verleyen #:
No worries.

Here is a stripped down version of the same problem, but without the possibility to verify, trace or reconstruct....


    static class pass_through
    { public:
        string _type;
        string _msg;
        pass_through() : _msg (NULL)                            { };
        pass_through(const pass_through& s)                     { _msg = s._msg; _type = s._type; }
        pass_through* msg(const string in, const string t_in)   { 
                                                                    _type = t_in; 
                                                                    _msg = in; 
                                                                    ResetLastError(); 
                                                                    return(GetPointer(this)); 
                                                                }
        template <typename T>
        T operator*(T in)                                       {
                                                                    const int err_no = GetLastError();
                                                                    const string _typename = typename(T);
                                                                    printf("%s; %s", 
                                                                        _msg, 
                                                                        (err_no != ERR_SUCCESS) ? StringFormat("Error: %i", err_no) : "");
                                                                    _msg = NULL;
                                                                    return(in);
                                                                }
    } dbg_mql_api_retval;

    
    template <typename T>
    const string    var_out(const string name, T val, const int shift = 0, const string prefix = "", const int offset = 0)
    { return(StringFormat("%s[xxx]  %-" + IntegerToString(60 - ((offset < 60) ? offset : NULL)) + "s = '%s'", prefix, name, typename(val))); }


void OnInit()
{
    #define ____DBG_MSG_VAR(x)                          printf("   " + "   " + "%s>%s< %s(){ @%i: %s }", "", __FILE__, __FUNCTION__, __LINE__, var_out(#x, (x), 0))
    #define TEST_DBG_MSG_MQLFUNC_RETURN(x, y)           dbg_mql_api_retval.msg(x, y) *
    #define TimeCurrent                                 TEST_DBG_MSG_MQLFUNC_RETURN("TimeCurrent", "datetime") TimeCurrent
    ____DBG_MSG_VAR(TimeCurrent());


}

@William Roeder


Hope this is still enough

 
Dominik Christian Egert #:

Here is a stripped down version of the same problem, but without the possibility to verify, trace or reconstruct....


@William Roeder


Hope this is still enough

Tried it. Perfect.
 
Alain Verleyen #: Tried it. Perfect.

Thank you.

 

Thank you all.
Fixed.

 
Ilyas #:

Thank you all.
Fixed.

Nice. Thank you.
 
Ilyas #:

Thank you all.
Fixed.

Forum on trading, automated trading systems and testing trading strategies

Possible Preprocessor Bug

Dominik Christian Egert, 2023.04.30 13:13

Additionally, I noticed the macro-operator # for stringifying, does not work properly, as it removes all '"' instead of escaping them properly, also whitespaces are being removed, giving false results in the outcome.


The bug of self-referential macro was fixed. https://gcc.gnu.org/onlinedocs/cpp/Self-Referential-Macros.html

But, there is still a problem with stringification operator # as reported above.

#define FORMAT(x)            StringFormat("[%s]", x)
#define EXPAND_MACRO(macro)  printf("%s", #macro)

void OnStart()
  {
   EXPAND_MACRO( FORMAT("MT5") );
  }

// MT5 compiler output:
// StringFormat([%s],MT5)

// gcc preprocessor macro expansion (with option -E):
// printf("%s", "StringFormat(\"[%s]\", \"MT5\")");

// gcc compiler output:
// StringFormat("[%s]", "MT5")


Edited: I usually use this little macro for debugging.

It works badly with strings and whitespaces, due to the # operator bug. https://gcc.gnu.org/onlinedocs/cpp/Stringizing.html

#define PRINT(A)   Print(#A + " = ", (A))

void OnStart()
  {
   PRINT(SymbolInfoDouble("EURUSD", SYMBOL_ASK));
  }
// SymbolInfoDouble(EURUSD,SYMBOL_ASK) = 1.10654

It would be nice if it is: SymbolInfoDouble("EURUSD", SYMBOL_ASK) = 1.10654