reference-en
reference-en copied to clipboard
switch...case reference confusing
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, ...).
A few points:
- 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.
- 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.
- The case values must be constants.
- 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.
@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 ;)
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: https://github.com/arduino/reference-en/pull/937).