Home Dashboard Directory Help
Search

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


Status: 

Closed
 as Fixed Help for as Fixed


4
0
Sign in
to vote
Type: Suggestion
ID: 584688
Opened: 8/9/2010 3:12:17 AM
Access Restriction: Public
0
Workaround(s)
view

Description

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.
Details
Sign in to post a comment.
Posted by Microsoft on 8/20/2010 at 2:24 PM
Hello,

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(http://support.microsoft.com)
Sign in to post a workaround.
File Name Submitted By Submitted On File Size  
AllowTypeSafeMinMax.zip 8/9/2010 777 KB