Menu

windows min max vs std - use (std::min)(...)

2006-11-02
2013-04-08
  • Nobody/Anonymous

    Windows min and max macros are undefined by SmartWin, which is bad in many cases.
    At least one of the tests does not compile: project "Canvas", file "canvas_all.cpp", when
    "#define UseGdiPlus 1"
    is uncommented.

    The workaround is simple: _never_ undefine min and/or max, but convert code like this:
    "std::min(a,b)"
    to
    "(std::min)(a,b)"

    The same applies to std::numeric_limits<...>::min and std::numeric_limits<...>::max.

    It is always worth to have a look at boost, you find the same solution to this issue too.

     
    • andrew7

      andrew7 - 2006-11-03

      I have checked in your solution to the CVS.  Canvas now compiles with UseGdiPlus defined.
      Min and max are no longer #undef, and I replaced occurrences of std::min( ) with (std::min)( ) etc.

      I only checked in the removal of min/max from VCDesktopHeaders.h
      I have not removed the max/min undef from the other platform headers yet.

      Thanks for the bringing the problem and the solution to our attention.

      Andrew

       

Log in to post a comment.