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

DISABLED macro may conflict with sketches #2072

Closed
ewasscher opened this issue May 30, 2016 · 1 comment
Closed

DISABLED macro may conflict with sketches #2072

ewasscher opened this issue May 30, 2016 · 1 comment

Comments

@ewasscher
Copy link

ewasscher commented May 30, 2016

Basic Infos

The macro DISABLED as defined in Arduino.h may conflict with some sketches.

Hardware

Hardware: All ESP8266
Core Version: 2.2.0

Description

The macro DISABLED as defined in Arduino.h may conflict with some sketches when DISABLED is defined in the sketch or library. Changing from a generic name like "DISABLED" to a more specific name like "ESP8266_INT_DISABLED" would help to avoid collisions like this. Would this be an option?

Sketch

#include <Arduino.h>

enum class State : uint8_t {
  DISABLED,
  WAITING,
  READING,
  CHECKSUM,
};

void setup() {

}

void loop() {

}

Debug Messages

Build options changed, rebuilding all
In file included from /tmp/arduino_modified_sketch_437587/sketch_may30b.ino:1:0:
/home/ewasscher/.arduino15/packages/esp8266/hardware/esp8266/2.2.0/cores/esp8266/Arduino.h:76:19: error: expected identifier before numeric constant
 #define DISABLED  0x00
                   ^
/tmp/arduino_modified_sketch_437587/sketch_may30b.ino:4:3: note: in expansion of macro 'DISABLED'
   DISABLED,
   ^
/home/ewasscher/.arduino15/packages/esp8266/hardware/esp8266/2.2.0/cores/esp8266/Arduino.h:76:19: error: expected '}' before numeric constant
 #define DISABLED  0x00
                   ^
/tmp/arduino_modified_sketch_437587/sketch_may30b.ino:4:3: note: in expansion of macro 'DISABLED'
   DISABLED,
   ^
/home/ewasscher/.arduino15/packages/esp8266/hardware/esp8266/2.2.0/cores/esp8266/Arduino.h:76:19: error: expected unqualified-id before numeric constant
 #define DISABLED  0x00
                   ^
/tmp/arduino_modified_sketch_437587/sketch_may30b.ino:4:3: note: in expansion of macro 'DISABLED'
   DISABLED,
   ^
sketch_may30b:8: error: expected declaration before '}' token
 };
 ^
exit status 1
expected declaration before '}' token

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@matthijskooijman
Copy link

Alternatively, using a global constant will reduce the impact of this:

const uint8_t DISABLED = 0;

This will still conflict with global variables or constants, but will allow using DISABLED as an identifier in other places (parameter names, member names, etc.). Using a constant instead of a define in this way should not influence performance (generated code is typically identical).

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

3 participants