Using the new Arduino IDE for ESP8266 and found bugs, report them here

Moderator: igrr

User avatar
By martinayotte
#25994 I had a case where I need to call min() function, I've simply got the following error : :?
So, I used the suggested alternative std::min() ...

Code: Select allSketch_Buffet.ino:810:57: error: 'min' was not declared in this scope
Sketch_Buffet.ino:810:57: note: suggested alternative:
In file included from /home/martin/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9/xtensa-lx106-elf/include/c++/4.8.2/memory:62:0,
                 from /home/martin/.arduino15/packages/esp8266/hardware/esp8266/1.6.5-947-g39819f0/cores/esp8266/FS.h:25,
                 from Sketch_Buffet.ino:6:
/home/martin/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algobase.h:239:5: note:   'std::min'
     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
User avatar
By lethe
#26009 You need to include <algorithm> to use std::min, see http://en.cppreference.com/w/cpp/algorithm/min
Of course you can also define a simple macro:
Code: Select all#define min(X, Y) (((X)<(Y))?(X):(Y))

Be careful though, if you pass something like x++ to the macro, the statement might be evaluated more than once and x ends up being incremented twice.
User avatar
By martinayotte
#26026 I mean, normally on Arduino, such as Uno or Nano, we don't need to include any thing and min()/max() are already defined.
Here, on ESP, I had to specify the "std::" namespace (I didn't have to add a include), and it worked !
So, it is a small glitch, but if someone is porting a existing library, he will probably faced that ...

EDIT: I didn't have to add the include simply because it was already included indirectly.