Arduino icon indicating copy to clipboard operation
Arduino copied to clipboard

Pollution of global namespace due to using namespace EspSoftwareSerial;

Open RobertGnz opened this issue 1 year ago • 10 comments

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

RobertGnz avatar Dec 17 '23 23:12 RobertGnz

Also see https://github.com/plerup/espsoftwareserial/issues/301

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

mcspr avatar Dec 18 '23 02:12 mcspr

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

RobertGnz avatar Dec 18 '23 12:12 RobertGnz

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"

RobertGnz avatar Dec 18 '23 20:12 RobertGnz

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

mcspr avatar Dec 19 '23 06:12 mcspr

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.

RobertGnz avatar Dec 19 '23 13:12 RobertGnz

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).

Pablo2048 avatar Dec 19 '23 14:12 Pablo2048

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 ?

RobertGnz avatar Dec 19 '23 16:12 RobertGnz

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 ...

Pablo2048 avatar Dec 19 '23 18:12 Pablo2048

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.

RobertGnz avatar Dec 22 '23 16:12 RobertGnz

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

Pablo2048 avatar Dec 24 '23 07:12 Pablo2048