DhrBaksteen / ArduinoOPL2

Arduino library for use with the OPL2 board (YM3812) and OPL3Duo (YMF262)
MIT License
195 stars 39 forks source link

min / max macros in opl2.h cause issues when using opl2.h with other libraries #73

Closed isnotinvain closed 3 years ago

isnotinvain commented 3 years ago

Filing this so I don't forget -- I'll try and send a PR with a fix soon.

I'm not a C++ expert but I did some googling after hitting some compiler errors when I tried to use std::min in a file that includes OPL2.h and found that defining min/max macros is discouraged (for this reason).

This workaround works:

#include <OPL2.h>
#undef min
#undef max

... rest of your code... 

I think probably std::min and std::max could be used instead, at least for raspberry pi. Or this macro could move to the relevant cpp files instead.

DhrBaksteen commented 3 years ago

In the library and examples these functions are only used to clamp values to a valid range. Using std:: is not an option for Arduino due to its memory limitations. The upcoming library update contains a helper fucntion clamp to take care of this and that's also where the Arduino / Raspberry Pi / others distinction will be made to prevent spreading complier directives throughout the code in order to keep it simple and readable.

isnotinvain commented 3 years ago

ok sounds good, thanks!

DhrBaksteen commented 3 years ago

Please reopen if the issue persists

isnotinvain commented 3 years ago

Great, thanks! I'll back out my undefines and see how it goes