reference-en icon indicating copy to clipboard operation
reference-en copied to clipboard

switch...case reference confusing

Open sterretjeToo opened this issue 3 years ago • 2 comments

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, ...).

sterretjeToo avatar May 22 '21 18:05 sterretjeToo

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.

MalcolmBoura avatar May 23 '21 11:05 MalcolmBoura

@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 ;)

sterretjeToo avatar May 27 '21 11:05 sterretjeToo

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).

karlsoderby avatar Nov 20 '23 15:11 karlsoderby