iwanders / OBD9141

A class to read an ISO 9141-2 port found in OBD-II ports.
MIT License
227 stars 70 forks source link

Remove unnecessary and not portable min(). #36

Closed iwanders closed 2 years ago

iwanders commented 2 years ago

The check is enforced by line 171.

This caused an issue in #35;

C:\Users\USER\Documents\Arduino\libraries\OBD9141-master\src\OBD9141.cpp:179:65: error: no matching function for call to 'min(uint8_t&, int)'
     for (uint8_t i=0; i < min(answer_length, OBD9141_BUFFER_SIZE); i++){
                                                                 ^

Compiling for arduino 1.8.5 (which I had on my computer, more recent version may be different?) gives;

OBD9141.cpp:179:27: error: 'min' was not declared in this scope
     for (uint8_t i=0; i < min<uint8_t>(answer_length, OBD9141_BUFFER_SIZE); i++){
                           ^
OBD9141.cpp:179:38: error: expected primary-expression before '>' token
     for (uint8_t i=0; i < min<uint8_t>(answer_length, OBD9141_BUFFER_SIZE); i++){
                                      ^
exit status 1

Ultimately, it doesn't matter as the check here enforces that answer_length is always less than or equal to OBD9141_BUFFER_SIZE. So I'm confident we can remove this non-portable min call.

Gcopper22 commented 2 years ago

After i had replaced the line 179 ,the compiler completed successfully ,also checked on a vehicle and work correctly with debug mode of course. Nice work.