-
Notifications
You must be signed in to change notification settings - Fork 520
Move global declarations to a namespace #1401
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
base: develop
Are you sure you want to change the base?
Conversation
…id having Particle APIs declared in the global namespace
That's a good idea. 👍 Due to how the wiring preprocessor works, it needs to be documented that both the new define and the Particle include need to be added. For a refresher on how the preprocessor works, see the preprocessor description in the docs. For example this wouldn't work in the Web IDE:
This would work:
We also document using |
That's a good point, Julien. Good to know that the Web IDE is smart enough to not pre-include any header files unconditionally. |
It would be nice to see tests affirming that global symbols such as |
Is this a safe change? is it something we should queue up for the 2.x release in case there are breaking changes? I would like to see the API test suite expanded to cover the entire API and become our definitive reference of what is in the global and particle namespaces. |
Let's document the macro in https://docs.particle.io/reference/device-os/firmware/photon/#preprocessor |
Problem
Particle APIs get pulled into the global namespace and cause conflicts with an application code. This behavior cannot be overridden by application developers.
Solution
Add
PARTICLE_NO_GLOBAL_NAMESPACE
macro that can be defined by applications to avoid having Particle APIs declared in the global namespace.Note: This PR doesn't attempt to move all current APIs to the
particle
namespace, and many existing classes and functions are still declared in the global namespace directly. I suggest we start moving such declarations to namespaces iteratively, on occasion.Steps to Test
wiring/api
test should compile successfully.Example App
References
Completeness