Opened 8 years ago

Closed 5 years ago

#6192 closed task (wontfix)

Switch all C++ usages of ABS, MIN, and MAX macros to std::{abs,min,max}

Reported by: Kurt Schwehr Owned by: Kurt Schwehr
Priority: normal Milestone: closed_because_of_github_migration
Component: default Version: svn-trunk
Severity: normal Keywords: macros
Cc:

Description

In the vain of (almost) always preferring functions to macros, GDAL should use the std:: version for C++ code.

Examples of converting: r31275, r31273 + r31274

There are still C usages:

find . -name \*.c | xargs egrep -l '[^a-zA-Z_](MIN|MAX|ABS)[^a-zA-Z_]' | egrep -v 'lib(csf|jpeg|png|geotiff)|giflib|degrib18'
./ogr/ogrsf_frmts/dgn/dgndump.c
./ogr/ogrsf_frmts/avc/avc_bin.c
./ogr/ogrsf_frmts/avc/avc_binwr.c
./ogr/ogrsf_frmts/avc/avc_rawbin.c
./ogr/ogrsf_frmts/avc/avc_e00gen.c
./ogr/ogrsf_frmts/avc/avc_e00parse.c
./ogr/ogrsf_frmts/shape/shpopen.c
./ogr/osr_cs_wkt.c
./frmts/nitf/nitffile.c
./frmts/nitf/nitfimage.c
./frmts/gxf/gxfopen.c
./frmts/dted/dted_ptstream.c
./frmts/dted/dted_api.c
./frmts/dted/dted_create.c
./apps/gdaltindex.c

Can we convert any of these files to C++?

Change History (4)

comment:1 by Kurt Schwehr, 8 years ago

  rawdataset.cpp:179:21: [0;1;31merror:  call to 'abs' is ambiguous
        nLineSize = std::abs(nPixelOffset) * nBlockXSize;
                    ^~~~~~~~
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:660:1: [0;1;30mnote: candidate function
abs(float __x) _NOEXCEPT {return fabsf(__x);}

 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:664:1: [0;1;30mnote: candidate function
abs(double __x) _NOEXCEPT {return fabs(__x);}

 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:668:1: [0;1;30mnote: candidate function
abs(long double __x) _NOEXCEPT {return fabsl(__x);}

http://en.cppreference.com/w/cpp/numeric/math/abs says long long abs( long long n ); is C++11.

Confusion follows...

comment:2 by Kurt Schwehr, 8 years ago

r31276 should fix the mac build. integer abs templates are in cstdlib, whereas cmath provides the floating point templates.

comment:3 by Even Rouault, 8 years ago

avc and shapelib have "upstream" projects (although rather inactive those last years). Other files are pretty much internal to GDAL. Although if we kill all C files, I'm not sure how we're going to verify that the public headers can still be included from a pure C file, as we don't have any .c files in autotest/cpp anymore. Might be good to add at least one.

comment:4 by Even Rouault, 5 years ago

Milestone: closed_because_of_github_migration
Resolution: wontfix
Status: newclosed

This ticket has been automatically closed because Trac is no longer used for GDAL bug tracking, since the project has migrated to GitHub. If you believe this ticket is still valid, you may file it to https://github.com/OSGeo/gdal/issues if it is not already reported there.

Note: See TracTickets for help on using tickets.