Search code examples
c++preprocessor

Can I escape (suppress) C preprocessor macro expansion


I used the following code:

auto t = numeric_limits<decltype(m)>::max() - 1;

Later, I needed to #include <Windows.h> which has #define max(a, b) directive, so I can not use ::max() method. Is there a way to suppress macro expansion when calling ::max() without using #undef max?


Solution

  • Define NOMINMAX in compiler options or before you include windows.h:

    #define NOMINMAX
    #include <windows.h>