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

Improve mocks of builtin macros #133

Closed
ianfixes opened this issue Aug 8, 2019 · 0 comments · Fixed by #194
Closed

Improve mocks of builtin macros #133

ianfixes opened this issue Aug 8, 2019 · 0 comments · Fixed by #194
Labels
arduino mocks Compilation mocks for the Arduino library enhancement New feature or request

Comments

@ianfixes
Copy link
Collaborator

ianfixes commented Aug 8, 2019

A post to the arduino developers' mailing list suggests a smarter way to do macros for (e.g.) max using "statement expressions":

#define max(a,b) \
  ({ typeof (a) _a = (a); \
      typeof (b) _b = (b); \
    _a > _b ? _a : _b; })

Adopting this will prevent double-evaluating a and b if for some reason they themselves are expressions with side effects.

@ianfixes ianfixes added enhancement New feature or request arduino mocks Compilation mocks for the Arduino library labels Aug 8, 2019
matthijskooijman added a commit to matthijskooijman/arduino_ci that referenced this issue Aug 26, 2020
This replaces the macros in AvrMath.h with template functions when
included from C++. This prevents name clashes with e.g. the `std::min`
function or similar methods or namespace-local functions. For C, this
still uses a macro (lacking templates), but an improved version that
prevents double evaluation of arguments.

This code is based on the ArduinoCore-API repository, which is in the
process of become the single source of all non-architecture-specific
Arduino API code:

    https://github.com/arduino/ArduinoCore-API/blob/master/api/Common.h

There, only `min` and `max` have been replaced by template functions,
but others will probably follow as well:

    arduino/ArduinoCore-API#85

This fixes Arduino-CI#133.
@matthijskooijman matthijskooijman mentioned this issue Aug 26, 2020
matthijskooijman added a commit to matthijskooijman/arduino_ci that referenced this issue Nov 6, 2020
This replaces the macros in AvrMath.h with template functions when
included from C++. This prevents name clashes with e.g. the `std::min`
function or similar methods or namespace-local functions. For C, this
still uses a macro (lacking templates), but an improved version that
prevents double evaluation of arguments.

This code is based on the ArduinoCore-API repository, which is in the
process of become the single source of all non-architecture-specific
Arduino API code:

    https://github.com/arduino/ArduinoCore-API/blob/master/api/Common.h

There, only `min` and `max` have been replaced by template functions,
but others will probably follow as well:

    arduino/ArduinoCore-API#85

This fixes Arduino-CI#133.
matthijskooijman added a commit to matthijskooijman/arduino_ci that referenced this issue Nov 6, 2020
This replaces the macros in AvrMath.h with template functions when
included from C++. This prevents name clashes with e.g. the `std::min`
function or similar methods or namespace-local functions. For C, this
still uses a macro (lacking templates), but an improved version that
prevents double evaluation of arguments.

This code is based on the ArduinoCore-API repository, which is in the
process of become the single source of all non-architecture-specific
Arduino API code:

    https://github.com/arduino/ArduinoCore-API/blob/master/api/Common.h

There, only `min` and `max` have been replaced by template functions,
but others will probably follow as well:

    arduino/ArduinoCore-API#85

This fixes Arduino-CI#133.
matthijskooijman added a commit to matthijskooijman/arduino_ci that referenced this issue Nov 6, 2020
This replaces the macros in AvrMath.h with template functions when
included from C++. This prevents name clashes with e.g. the `std::min`
function or similar methods or namespace-local functions. For C, this
still uses a macro (lacking templates), but an improved version that
prevents double evaluation of arguments.

This code is based on the ArduinoCore-API repository, which is in the
process of become the single source of all non-architecture-specific
Arduino API code:

    https://github.com/arduino/ArduinoCore-API/blob/master/api/Common.h

There, only `min` and `max` have been replaced by template functions,
but others will probably follow as well:

    arduino/ArduinoCore-API#85

This fixes Arduino-CI#133.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arduino mocks Compilation mocks for the Arduino library enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant