vendredi 4 juin 2021

Using #define the wrong way round works for calling functions. Why? [closed]

C and C++ documentation for the use of #define suggests that this should not work as I am using the define to replace the text MyFunc() with _myfunc(), which is a function that does not exist:

#define MyFunc _myfunc

void MyFunc()
{
    cout << "This Prints!" << endl;
}

int Main()
{
    _myfunc();
    return 0;
}

My guess is that the compiler is being clever. It knows that _myfunc() does not exists and therefore does not replace the text and simple uses MyFunc().

I can't find any documentation to support this theory. Does anyone know whether this is correct?

Aucun commentaire:

Enregistrer un commentaire