michalmonday / CSV-Parser-for-Arduino

It turns CSV string into an associative array (like dict in python)
MIT License
57 stars 12 forks source link

Compile warnings in CSV_Parser.cpp #21

Closed RealJamieRI closed 10 months ago

RealJamieRI commented 1 year ago

Should I care about some compile warnings?

I installed the CSV Parser 1.0.1 library in the Arduino IDE 2.0.4 and adding #include to one of my source files.

Without other code, the IDE compiler says:

c:\Users\jamie\OneDrive\Documents\Arduino\libraries\CSV_Parser\CSV_Parser.cpp: In constructor 'CSV_Parser::CSV_Parser(const char*, const char*, bool, char, char)': c:\Users\jamie\OneDrive\Documents\Arduino\libraries\CSV_Parser\CSV_Parser.cpp:72:14: warning: converting to non-pointer type 'int' from NULL [-Wconversion-null] 72 | rows_count(NULL), | ^~~~ c:\Users\jamie\OneDrive\Documents\Arduino\libraries\CSV_Parser\CSV_Parser.cpp:82:29: warning: list-initializer for non-class type must not be parenthesized 82 | header_parsed(!has_header_) | ^ c:\Users\jamie\OneDrive\Documents\Arduino\libraries\CSV_Parser\CSV_Parser.cpp:81:15: warning: converting to non-pointer type 'uint16_t' {aka 'short unsigned int'} from NULL [-Wconversion-null] 81 | current_col(NULL), | ^~~~ TLDR

About me: I am a career EE just learning C++, Github, and Arduino with long past coding experience using K&R Microsoft C in the 90's ... This being about your library, I thought a library warning would be of interest here. Is that right?

Thanks! Jamie

Jusufs commented 10 months ago

I have also some warnings in IDE 2.0 compilation.

I'm calling CSV Parser from main: CSV_Parser cp(pay1, /*format*/ "sLfffs", /*has_header*/ true, /*delimiter*/ ';');

I tried https://chat.openai.com/ and maked some hope good code corrections in CSV_Parser.cpp

`CSV_Parser::CSVParser(const char s, const char fmt, bool hasheader, char delimiter_, char quotechar) : fmt( strdup_ignoringu(fmt) ),

//rows_count(NULL), rows_count(0),

cols_count( strlen_ignoringu(fmt) ), has_header(hasheader), delimiter(delimiter_), quote_char(quotechar), delimchars({'\r', '\n', delimiter, 0}), //whole_csv_supplied(false), whole_csv_supplied(bool(s) ? true : false), // in constructor where whole csv is not supplied at once it should be set to false

//leftover(NULL), //current_col(NULL), leftover(0), current_col(0),

header_parsed(!hasheader) // header_parsed = !hasheader;`

But still one warning: c:\Users\jozef\Documents\Arduino\libraries\CSV_Parser\CSV_Parser.cpp: In constructor 'CSV_Parser::CSV_Parser(const char*, const char*, bool, char, char)': c:\Users\jozef\Documents\Arduino\libraries\CSV_Parser\CSV_Parser.cpp:89:29: warning: list-initializer for non-class type must not be parenthesized header_parsed(!has_header_) ^

With originally CSV_Parse.cpp i have additional warning c:\Users\jozef\Documents\Arduino\libraries\CSV_Parser\CSV_Parser.cpp:82:29: warning: converting to non-pointer type 'int' from NULL [-Wconversion-null] header_parsed(!hasheader)

header_parsed = !hasheader; doesn't help

michalmonday commented 10 months ago

@RealJamieRI Hello, sorry for such late reply, I completely forgot about the issue.

@Jusufs Thank you very much for suggestions to fix it.

In the 1.2.1 version there should be no warnings.

Jusufs commented 10 months ago

Thanks for rapid reaction Michal. I confirm, that 1.2.1 version is compiled without warnings.

It seems,that CSV_Parser needs floats with "." decimal delimiter.

I have a source from web page with '," delimiter for floats and delimiter for colums is ';'. Before parsing I need to replace ',' delimiters with '.' It's OK, because ',' is often used as values delimiter, therefore it is a wrong candidate for decimal.

Jozef

Jusufs commented 10 months ago

Please insert this information about decimal delimiter '.' for float parsing in comments of your package. Thanks - close ticket - all done :0)