Skip to content

switch...case reference confusing #830

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
sterretjeToo opened this issue May 22, 2021 · 3 comments
Closed

switch...case reference confusing #830

sterretjeToo opened this issue May 22, 2021 · 3 comments
Labels

Comments

@sterretjeToo
Copy link

https://www.arduino.cc/reference/en/language/structure/control-structure/switchcase/

Allowed data types according to the reference are int and char. However, any integral type is allowed (e.g. uint32_t, byte, ...).

@per1234 per1234 added the bug label May 22, 2021
@MalcolmBoura
Copy link
Contributor

MalcolmBoura commented May 23, 2021

A few points:

  1. Should mention including the stdint.h header file and extern wrapper. cstdint should be provided but last time I tried to include it I got a file not found error. Really Arduino.h should do the inclusion, see next point.
  2. In my opinion, int, unsigned etc should be deprecated because what you actually get depends on the platform. The types from stdint.h should be the default. I only use char when it is actually a character.
  3. The case values must be constants.
  4. When falling through from one case to the next then a comment, eg "// fall through", should usually be provided to indicate that the break has been omitted deliberately.

@sterretjeToo
Copy link
Author

@MalcolmBoura,

Regarding (1, "mention including stdint.h"), you will have to keep the intended audience in mind; it's beginners in the language and they don't really care. I would prefer the format to be that of Linux man pages ;)

Regarding (4), there is no fall-through example so the point is a little moot. It's also the user's responsibility to document those cases ;)

@karlsoderby
Copy link
Collaborator

Hey guys, and sorry for the late response 😅 you are indeed accurate that any integral type is supported, and I have updated the article for that (here: #937).

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

No branches or pull requests

4 participants