Skip to content

SoftwareSerial breaks abs macro #30

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

Closed
florian-schweiger opened this issue Aug 10, 2018 · 2 comments · Fixed by #51
Closed

SoftwareSerial breaks abs macro #30

florian-schweiger opened this issue Aug 10, 2018 · 2 comments · Fixed by #51

Comments

@florian-schweiger
Copy link
Contributor

When I include SoftwareSerial.h, other libraries break because the abs(x) macro stops working. One particular library that stops functioning properly is uStepper.

The reason for it seems to be a section at the bottom of SoftwareSerial.h that undefines several macros:

// Arduino 0012 workaround
#undef int
#undef char
#undef long
#undef byte
#undef float
#undef abs
#undef round

I've commented this out in my project, and things are back to normal.

So I'm wondering, is this workaround still needed in the post-Arduino-0012 era?

@matthijskooijman
Copy link
Collaborator

I dug around a bit to see if I could find the origin of these lines, but it seems they were already present in the "NewSoftSerial" library that was merged into the Arduino core a long time ago (and renamed to "SoftwareSerial" there. That library was again based on ladyada's AFSoftSerial, but that did not have these lines. Unfortunately, it seems NewSoftSerial did not use any version control, and the changelog does not mention these either.

In any case, I can't quite see why these undefs are needed. They are at the bottom of SoftwareSerial.h, so they cannot affect the contents of SoftwareSerial.h above. They might be needed for SoftwareSerial.cpp, but then they should be moved there, and not "pollute" the global scope. However, you suggest things work just fine with these line removed, so I'd be in favor of removing them (the more predictable the global scope is, the better).

@cmaglie, @facchinm, would you agree?

@florian-schweiger, care to prepare a PR for this?

@facchinm
Copy link
Member

@matthijskooijman agree, let's get rid of that lines 🙂

florian-schweiger added a commit to florian-schweiger/ArduinoCore-avr that referenced this issue Nov 26, 2018
Removed #undefs in SoftwareSerial.h that were marked as Arduino 0012 workaround and that broke several macros, including abs.
See arduino#30
HMLeao pushed a commit to HMLeao/ArduinoCore-avr that referenced this issue May 22, 2019
Removed #undefs in SoftwareSerial.h that were marked as Arduino 0012 workaround and that broke several macros, including abs.
See arduino#30
sergey-sh pushed a commit to sergey-sh/HalfDuplexSoftwareSerial that referenced this issue Feb 28, 2023
Removed #undefs in SoftwareSerial.h that were marked as Arduino 0012 workaround and that broke several macros, including abs.
See arduino/ArduinoCore-avr#30
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

Successfully merging a pull request may close this issue.

3 participants