Skip to content

warnings in msvc about mix/max macro while windows.h is used in the project #762

Description

@crea7or

In the version 2.1.1, msvc generates a few warnings about std::numeric_limits<>::max() (and min) usage. This is because windows.h have their own min/max macros definitions in the global namespace (here is microsoft kb article about it..
warning exact text: warning C4003: not enough actual parameters for macro 'max'

possible fixes:
1)

#define NOMINMAX

#ifdef max
#undef max
#endif

#ifdef min
#undef min
#endif
  1. use additional parenthesis

std::numeric_limits<uint8_t>::max() => (std::numeric_limits<uint8_t>::max)()

First two methods can produce problems, due to use original windows min/max in the gdi and more.
the third method should be tested on the other compilers.

Source to reproduce the problem:

#include "stdafx.h"
#include "windows.h"
#include "json.hpp"

using json = nlohmann::json;

int main( int argc, char const *argv[] )
{
	json j;
	j[ "test" ] = 1;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions