Allow type safe alternatives for the min() and max() macros to be used in MFC projects. - by Frank Heimes

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 584688 Comments
Status Closed Workarounds
Type Suggestion Repros 0
Opened 8/9/2010 3:12:17 AM
Access Restriction Public


Please allow MFC headers to compile after defining type safe alternatives for the min()- and max() macros.

In the past, we had to fix subtle bugs in our code caused by inappropriate use of the min() and max() macros. These cause an automatic type conversion by the compiler, which may not lead to the desired results (e.g. when comparing signed/unsigned values or values of different size). Even worse, one of the argument to min() or max() may be evaluated twice, inadvertently.

Therefore we added code to the beginning of every project for mapping the default min() and max() macros to the definitions in std::min() and std::max(). This forces all calls to min() and max() to be type safe; i.e. the programmer must decide which types the compared values should have and perform an explicit type cast.

These type safe definitions to not compile for (very) few source code locations.
Sign in to post a comment.
Posted by Microsoft on 8/20/2010 at 2:24 PM

Thanks for the report. This issue has been fixed in MFC for the next major release of Visual Studio.

Pat Brenner
Visual C++ Libraries Development
Posted by Microsoft on 8/9/2010 at 8:34 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(