-
Notifications
You must be signed in to change notification settings - Fork 78
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
Avoid creating constants and macros in the global namespace #315
Comments
Another example of this practice resulting in name collisions: #280 |
We also have this problem with macros such as the ones defined here: ArduinoIoTCloud/src/property/Property.h Lines 50 to 52 in 925922b
The workaround is to undef the symbol in the user sketch before including other libraries: #undef setAttribute(x)
#include <TFT_eSPI.h> However this library should be fixed to maximize its compatibility and avoid any overlap with other symbols in the global namespace. |
Since the macro is only being used internally inside the various Cloud* types, I suggest to undef at the end of all .h using it (https://github.com/arduino-libraries/ArduinoIoTCloud/search?q=setAttribute) |
@facchinm With that approach wouldn't you still override any existing macros created by other libraries imported before this one? Wouldn't it be better to switch to namespaced symbols such as proper functions, constexprs or even just prefixing the macros with |
These symbols cannot be turned into proper functions due to stringification, but since they are not intended to be used by the end user we can safely prefix with |
@alranel regarding ArduinoIoTCloud/src/property/Property.h Lines 130 to 132 in 9c6d5d7
The first step to remove /cc @eclipse1985 |
This library defines some constants in the global namespace, such as the following ones:
ArduinoIoTCloud/src/ArduinoIoTCloud.h
Lines 51 to 56 in 451d57d
This generates errors whenever they are also defined by other libraries, preventing their coexistence. For instance,
the ArduinoBLE library defines both(not anymore, constants were renamed in ArduinoBLE) and in general it is very likely to find constants named like this.READ
andWRITE
It would be nice to avoid polluting the global namespace, obviously in a retrocompatible way...
The text was updated successfully, but these errors were encountered: