Skip to content

Use of macros for pin remapping breaks user code and libraries #9150

Closed
@tttapa

Description

@tttapa

Board

Arduino Nano ESP32

Version

latest master (checkout manually)

Description

Redefining Arduino API functions like digitalWrite as macros is problematic: It breaks user code and libraries because the macros do not honor C++ namespace rules.

The code in question was added to cores/esp32/io_pin_remap.h in 7d26b07 in order to add support for the Arduino Nano ESP32.

Background: I'm the author of the Control Surface, which has member functions with names like digitalWrite: https://github.com/tttapa/Control-Surface/blob/7fbff1e994dea4fc249da2b88d4df05f62f7fec9/src/AH/Hardware/ExtendedInputOutput/ExtendedIOElement.hpp#L121

Sketch

class MyClass {
  void digitalWrite() { /* something */ }
};

namespace custom {
  void digitalWrite() { /* something */ }
}

void setup() {}
void loop() {}

Debug Message

sketch_jan21b.ino:2:21: error: macro "digitalWrite" requires 2 arguments, but only 1 given
    2 |   void digitalWrite() { /* something */ }
      |                     ^
In file included from ~/.arduino15/packages/esp32/hardware/esp32/3.0.0-alpha3/cores/esp32/Arduino.h:239,
                 from /tmp/arduino/sketches/5B2320DC96E62936CEB584BE31053B9E/sketch/sketch_jan21b.ino.cpp:1:
~/.arduino15/packages/esp32/hardware/esp32/3.0.0-alpha3/cores/esp32/io_pin_remap.h:46: note: macro "digitalWrite" defined here
   46 | #define digitalWrite(pin, val)                      digitalWrite(digitalPinToGPIONumber(pin), val)
      |

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions