arduino / arduino/ArduinoCore-avr

Add "namespace" prefixes to macro definitions in headers to avoid collisions

Open
#405 0 comments 2 reactions 0 assignees View on GitHub
enhancement
Dominant language
C
Stars
1.5k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

No macro in the core headers are prefixed! This leads to macro errors in user-made libraries.

For example, instead of

``` c++
#define TEST_MODE 2
```
in the USBCore.h, something like
``` c++
#define ARDUINO_TEST_MODE 2
```
should have been used.

Real life example. I wrote a library with a scope enum like:
``` c++
enum class Test
{
TEST_MODE = 0x80
}
```
`TEST_MODE` is the name of the variable as defined in the documentations of the device that needed programming.
No errors were reported from the GCC Compiler on other Arduino except on the Nano, which supports the USB. The USBCore.h header gets included automatically overlapping the `#define TEST_MODE 2` as mentioned before with the `enum TEST_MODE`.

Prefixing macros and types are considered good practices, and should be a required considering the number of user-made libraries that the Arduino has.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with USBCore.h and inspect the other core headers for unprefixed macro definitions like TEST_MODE. Trace which headers are included automatically on USB-capable boards, then determine the full set of definitions that need consistent prefixes. Done means user-defined names such as TEST_MODE no longer collide with core macros.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
embedded-iot
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.