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

_BV macro missing in unit test #240

Open
RobTillaart opened this issue Dec 9, 2020 · 6 comments
Open

_BV macro missing in unit test #240

RobTillaart opened this issue Dec 9, 2020 · 6 comments
Labels
arduino mocks Compilation mocks for the Arduino library question Further information is requested

Comments

@RobTillaart
Copy link

Issue Summary

problem occurred in a unit test where I used the _BV() macro which is normally supported in Arduino sketches.
Replacing the test code with a normal shift (1UL << (x)) solved the issue.
However people might expect to be able to use the same code constructs as in the sketches / libraries,
just after #include "Arduino.h"

@ianfixes ianfixes added this to the 2020 Wrapup milestone Dec 23, 2020
@ianfixes
Copy link
Collaborator

Is this the use of a documented or undocumented Arduino API? My search suggests that it's not universal:

via avrfreaks.net

as far as I'm aware, _BV is only defined in the avr-libc headers. Extracted from avr/sfr_defs.h in avr-libc:

#define _BV(bit) (1 << (bit))

@matthijskooijman
Copy link
Collaborator

I'm pretty sure that _BV is not documented Arduino API. As you mentioned, it is made available by avr-libc, and also used by the AVR Arduino core, so it is de facto exposed by Arduino.h on AVR, but not guaranteed on other platforms (some might define it, but you can't really rely on this). I would even say that code should not rely on Arduino.h exposing _BV, even on AVR, and they should just include avr/sfr_defs.h or some other header that includes that directly, but I guess there's too much code that already assumes that the macro is available on AVR.

I would suggest to add an avr/sfr_defs.h in Arduino-ci with this macro, and include that from Arduino.h on AVR only, for compatibility with AVR-specific sketches.

@ianfixes
Copy link
Collaborator

My sense is to only prioritize this if there is some "official" (Arduino-hosted) documentation explaining it, since there are still a bunch of official functions that need implementation.

@RobTillaart
Copy link
Author

low priority indeed, as workaround is simple.

Thoughts

  • maybe get usage out of core Arduino code?
  • check how often it is used?

@ianfixes
Copy link
Collaborator

Is the other option here to put it behind some kind of #ifdef? Maybe some more use cases here would sharpen the boundaries of this issue

@RobTillaart
Copy link
Author

As this issue has no reactions for 2 yrs the priority is low. For me I try not to use the macro (as macros can have side effects).

That said, I searched the Arduino Libraries section (1.8.19) and the BV macro is used in multiple libs incl SPI and SWSerial.
Maybe that is still a point of attention?

@ianfixes ianfixes added question Further information is requested arduino mocks Compilation mocks for the Arduino library labels Jan 20, 2023
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 question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants