Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nano_gfx_types.h defines macros which pollutes the global namespace and cause compile errors #146

Open
fergald opened this issue May 15, 2022 · 0 comments
Assignees

Comments

@fergald
Copy link

fergald commented May 15, 2022

The following code fails to compile when the #include is present

#include "ssd1306.h"

void setup() {
  Serial.println(std::numeric_limits<int16_t>::max());

}

void loop() {
}

The error is

sketch_may15a:4:52: error: macro "max" requires 2 arguments, but only 1 given
    4 |   Serial.println(std::numeric_limits<int16_t>::max());
      |                                                    ^
In file included from /home/fergal/Arduino/libraries/ssd1306/src/ssd1306.h:31,
                 from /home/fergal/Arduino/sketch_may15a/sketch_may15a.ino:1:
/home/fergal/Arduino/libraries/ssd1306/src/nano_gfx_types.h:40: note: macro "max" defined here
   40 | #define max(a,b) ((a)>(b)?(a):(b))
      | 
exit status 1
macro "max" requires 2 arguments, but only 1 given

The code above is just the simplest repro case. I ran into this in real life because esp8266/StreamString.h contains the following

    virtual int availableForWrite() override
    {
        return std::numeric_limits<int16_t>::max();
    }

In general you shouldn't define macros in .h files that will end up included by users of the library unless they are intended to be used by those users (and then naming them becomes tricky).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants