CubeCell-Arduino icon indicating copy to clipboard operation
CubeCell-Arduino copied to clipboard

pinMode should be a function, not a macro

Open jgromes opened this issue 3 years ago • 0 comments

Hi,

it seems that currently, pinMode() is a macro, as defined in https://github.com/HelTecAutomation/CubeCell-Arduino/blob/e15d5fdd5126bacf63116b846de79069389df9db/cores/asr650x/Arduino.h#L87

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.

jgromes avatar Oct 25 '21 16:10 jgromes