adafruit / Adafruit_MQTT_Library

Arduino library for MQTT support
MIT License
573 stars 291 forks source link

Fix min() usage when using STL C++ #95

Closed fpistm closed 6 years ago

fpistm commented 7 years ago

Using the https://github.com/stm32duino/Arduino_Core_STM32 with Adafruit_MQTT_Library, there is a build issue.

.../libraries/Adafruit_MQTT_Library/Adafruit_MQTT_Client.cpp: In member function 'virtual bool Adafruit_MQTT_Client::sendPacket(uint8_t*, uint16_t)':
.../libraries/Adafruit_MQTT_Library/Adafruit_MQTT_Client.cpp:84:38: error: no matching function for call to 'min(uint16_t&, int)'
       uint16_t sendlen = min(len, 250);
                                      ^
...
.../packages/STM32/tools/arm-none-eabi-gcc/6-2017-q2-update/arm-none-eabi/include/c++/6.3.1/bits/stl_algo.h:3453:5: note: candidate: template<class _Tp, class _Compare> _Tp std::min(std::initializer_list<_Tp>, _Compare)
     min(initializer_list<_Tp> __l, _Compare __comp)

This patch allows to use min function of the standard C++ library without break compatibility with the min() macro if STL C++ is not used.

fpistm commented 6 years ago

Is any chance to have this PR merged @ladyada ? Thanks in advance

ladyada commented 6 years ago

thank u!

fpistm commented 6 years ago

Thanks a lot @ladyada