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

pinMode should be a function, not a macro #200

Open
jgromes opened this issue Oct 25, 2021 · 0 comments
Open

pinMode should be a function, not a macro #200

jgromes opened this issue Oct 25, 2021 · 0 comments

Comments

@jgromes
Copy link

jgromes commented Oct 25, 2021

Hi,

it seems that currently, pinMode() is a macro, as defined in

#define pinMode(pin,mode) PINMODE_ ## mode(pin)

However, Arduino API specifies it should be a function in the global scope: https://github.com/arduino/ArduinoCore-API/blob/e03b65374c614130aa1b11597e07b3b5089a726d/api/Common.h#L95

All Arduino cores I have seen so far stick to this, CubeCell is the only exception. This leads to issues if the user decides to create his own class that contains a pinMode member function. For example, try to compile the following sketch:

class MyClass {
  public:
    MyClass() {};
    void pinMode(int a, int b) { _a = a; _b = b; };

  private:
    int _a, _b;
};

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

The preprocessor will attempt to replace the MyClass::pinMode() method, which will obviously then fail to build. This is causing incompatibility in my projects and is one of the reasons I wasn't able to support CubeCell in RadioLib.

The only workaround is to not use pinMode as a name for anything, which seems rather silly.

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

No branches or pull requests

1 participant