ben-strasser/fast-cpp-csv-parser

Working on VS 2019 with C++17 with small change to avoid conflict with min max macro

Closed this issue · 1 comments

I've got your CSV parser working fine on VS2019 C++17 with a four tiny changes.

(Thanks by the way its great.)

windows.h (which is often included by windows code) defines macros for min and max which conflict with std::numeric_limits::min() and std::numeric_limits::max(). This means that the compilation of csv.h fails with very confusing errors:

Error	C2143	syntax error: missing ';' before '{' csv.h 998	
Error	C2059	syntax error: ')' csv.h 998	
Error	C2589	'(': illegal token on right side of '::' csv.h 998	

There is a really really easy fix for this to wrap the min and max in parenthesis: here are the four lines involved (just search csv.h for "std::numeric_limits::") which include the change that fixes the compilation errors on windows.

x = (std::numeric_limits<T>::max)();    
x = (std::numeric_limits<T>::min)();  
if(x < ((std::numeric_limits<T>::min)()+y)/10){
if(x > ((std::numeric_limits<T>::max)()-y)/10){

and that means it compiles with code that includes min and max macros.

There is a workaround on windows which is to define NOMINMAX before including windows but as its such a simple change to csv.h perhaps you would consider making this change?

for reference the macros are defined in windows like this:

#ifndef NOMINMAX

#ifndef max
#define max(a,b)            (((a) > (b)) ? (a) : (b))
#endif

#ifndef min
#define min(a,b)            (((a) < (b)) ? (a) : (b))
#endif

#endif  /* NOMINMAX */

Thanks again for your great work

Thanks for the feedback. I changed the code as suggested.