Opened 8 years ago

Closed 7 years ago

#6704 closed task (fixed)

MIN and MAX macros to std::min and std::max

Reported by: Kurt Schwehr Owned by: Kurt Schwehr
Priority: normal Milestone:
Component: default Version: unspecified
Severity: minor Keywords:
Cc:

Description

Similar to #6700. Prefer std::min and std::max for better type checking and better optimization.

Error: Failed to load processor bash
No macro or processor named 'bash' found

http://stackoverflow.com/questions/1632145/use-of-min-and-max-functions-in-c

Change History (4)

comment:1 by Kurt Schwehr, 8 years ago

Initial test commit: r35962

comment:2 by Kurt Schwehr, 8 years ago

http://stackoverflow.com/questions/5004858/stdmin-gives-error

#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#define VC_EXTRALEAN

// Ugly:
// Add parentheses around function name.
(std::max)(a, b);
(std::min)(a, b); 

r35987 is my first try at fixing this error.

gdalwmsdataset.cpp(297) : error C2589: '(' : illegal token on right side of '::'
gdalwmsdataset.cpp(297) : error C2059: syntax error : '::'
gdalwmsdataset.cpp(301) : error C2589: '(' : illegal token on right side of '::'
gdalwmsdataset.cpp(301) : error C2059: syntax error : '::'
gdalwmsdataset.cpp(301) : error C2143: syntax error : missing '(' before '::'

Places of possible trouble:

find . -name \*.c -o -name \*.cpp -o -name \*.h | xargs grep windows | grep include
./frmts/gtiff/libtiff/tiffio.h:# include <windows.h>
./frmts/jpeg/libjpeg/jerror.c:#include <windows.h>
./frmts/pcidsk/sdk/port/io_win32.cpp:#include <windows.h>
./frmts/pcidsk/sdk/port/win32_mutex.cpp:#include <windows.h>
./frmts/png/libpng/pngconf.h:#  include <windows.h>
./frmts/vrt/vrtderivedrasterband.cpp:#include <windows.h>
./frmts/zlib/zconf.h:#    include <windows.h>
./gcore/gdaldllmain.cpp:#include <windows.h>
./ogr/ogr_geocoding.cpp:#include <windows.h>
./ogr/ogrsf_frmts/db2/ogr_db2.h:#  include <windows.h>
./ogr/ogrsf_frmts/geojson/libjson/json_util.c:# include <windows.h>
./ogr/ogrsf_frmts/sosi/fyba_melding.cpp:#include <windows.h>
./ogr/ogrsf_frmts/sqlite/ogrsqlitevfs.cpp:#include <windows.h>
./ogr/ogrsf_frmts/xls/ogrxlsdatasource.cpp:#  include <windows.h>
./port/cpl_atomic_ops.cpp:#include <windows.h>
./port/cpl_atomic_ops.cpp:#include <windows.h>
./port/cpl_conv.cpp:/*      will include the newline.  On windows, if the file happens      */
./port/cpl_getexecpath.cpp:#include <windows.h>
./port/cpl_multiproc.cpp:#include <windows.h>
./port/cpl_odbc.h:#  include <windows.h>
./port/cpl_recode_stub.cpp:#include <windows.h>
./port/cpl_recode_stub.cpp:# include <windows.h>
./port/cpl_spawn.cpp:#include <windows.h>
./port/cpl_spawn.h:#include <windows.h>
./port/cpl_vsil_win32.cpp:#include <windows.h>
./port/cpl_vsisimple.cpp:#include <windows.h>
./port/cplgetsymbol.cpp:#include <windows.h>

comment:3 by Kurt Schwehr, 7 years ago

Trying NOMINMAX in nmake.opt with r36003

comment:4 by Kurt Schwehr, 7 years ago

Resolution: fixed
Status: newclosed

I've done most of the changes that I can easily compile.

find . -name \*.cpp | egrep -v '/new/|old/' | xargs egrep -nH -e '[^A-Za-z_0-9"](MIN|MAX) *[(]' | egrep -v 'SELECT' | wc -l
      77

r36033 r36030 r36028 r36027 r36025 r36024 r36022 r36021 r36020 r36018 r36017 r36016 r36015 r36014 r36013 r36012 r36011 r36010 r36009 r36008 r36007 r36006 r36005 r36004 r36003 r36002 r36001 r36000 r35994 r35993 r35988 r35987 r35986 r35985 r35984 r35975

Note: See TracTickets for help on using tickets.