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

Pollution of global namespace due to using namespace EspSoftwareSerial; #9055

Open
RobertGnz opened this issue Dec 17, 2023 · 10 comments
Open

Comments

@RobertGnz
Copy link
Contributor

In version 3.1.1 of SoftwareSerial.h we have:

enum SoftwareSerialConfig {
SWSERIAL_5N1 = SWSERIAL_PARITY_NONE,
etc...

this was changed in version 3.1.2 with:

enum Config {
SWSERIAL_5N1 = SWSERIAL_PARITY_NONE,
etc...

which lead to a conflicting name problem when Config is used in an application program but with another definition despite the namespace statement added in SoftwareSerial.h version 3.1.2

@mcspr
Copy link
Collaborator

mcspr commented Dec 18, 2023

Also see plerup/espsoftwareserial#301

edit: nvm the code snippet, enum does not work like that (sadly)

@mcspr mcspr changed the title Bug in SoftwareSerial.h in version 3.1.2 Pollution of global namespace due to using namespace EspSoftwareSerial; Dec 18, 2023
@RobertGnz
Copy link
Contributor Author

RobertGnz commented Dec 18, 2023

Can't use 3.1.2 release because it should oblige to change all existing applications.

@RobertGnz
Copy link
Contributor Author

Also see plerup/espsoftwareserial#301

edit: nvm the code snippet, enum does not work like that (sadly)

The problem comes from the directive: " using namespace EspSoftwareSerial; " line 433 which is not a good pratice in terms of programming because it may lead to collision problem.

Please have a look at this page https://learn.microsoft.com/en-us/cpp/cpp/namespaces-cpp?view=msvc-170 and pay a special attention to the note in chapter "Using directives"

@mcspr
Copy link
Collaborator

mcspr commented Dec 19, 2023

What I mean, the fix should happen upstream first. Please re-read the issue I linked, swserial is an external lib :>

@RobertGnz
Copy link
Contributor Author

What I mean, the fix should happen upstream first. Please re-read the issue I linked, swserial is an external lib :>

You just linked back to this issue and nothing else.

@Pablo2048
Copy link

EspSoftwareSerial is external library, so @mcspr tries to say that you are barking on wrong tree here - please report the error in the original one, because the original repository has to be changed first (it's used as submodule).

@RobertGnz
Copy link
Contributor Author

EspSoftwareSerial is external library, so @mcspr tries to say that you are barking on wrong tree here - please report the error in the original one, because the original repository has to be changed first (it's used as submodule).

Where is the original repository ?

@Pablo2048
Copy link

@RobertGnz
Copy link
Contributor Author

Did you try to click https://github.com/esp8266/Arduino/tree/master/libraries at the library? It leads to https://github.com/plerup/espsoftwareserial/tree/bcfd6d10e6a45a0d07705d08728f293defe9cc1d ...

The problem comes because of the directive using namespace EspSoftwareSerial wich leads to a global pollution.

@Pablo2048
Copy link

Yes, exactly described here plerup/espsoftwareserial#301 as @mcspr told you... This is wrong repository as it has nothing to do with the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants