azure-sdk-for-cpp icon indicating copy to clipboard operation
azure-sdk-for-cpp copied to clipboard

Re-evaluate the use of the `NOMINMAX` coding pattern when including Windows.h across the SDK

Open ahsonkhan opened this issue 1 year ago • 0 comments

From @LarryOsterman:

We should never define NOMINMAX, instead you should use the (min) trick Anton used.

I understand that this is not one of our headers, but we should get out of the habit of using min and instead use (min) throughout the SDK. For better or worse, our customers absolutely can (and will) include windows.h before they include our SDK headers, which means that the NOMINMAX definition will be irrelevant, since the min and max macros would have already been defined.

An alternative is to include a #undef min at the beginning of source files, possibly as:

#if defined(min)
#undef min
#endif

to make the removal of the macro explicit.

That way we relegate the use of the (min) pattern to our headers only (where we cannot control what our customers have previously included).

ahsonkhan avatar May 23 '24 17:05 ahsonkhan