I noticed that a lot of example sketches that I download from here or elsewhere use int type constants and variables instead of byte even when byte would be enough:
const int LED = 13 ; // 13 is < 256, byte would be enough
With an 8 bit MCU I would think using byte would be better (faster and half the memory) than int.
My question is: is there a drawback in using byte rather than int or, putting it in another way, an advantage using int instead of byte when byte is enough?
Thot:
My question is: is there a drawback in using byte rather than int or, putting it in another way, an advantage using int instead of byte when byte is enough?
PaulS:
Using byte is generally better. Typing byte, instead of int, requires 33% more effort.
And using #define led 13 uses zero bytes.
const byte, const int, and #define should all use zero bytes unless you don't use any optimizations or take the address of the constant.
int is a standard C++ type and byte isn't, so int is more portable' and recognizable to people not used to arduino. uint8_t is more standard but more annoying to type, and in C and C++ you have to include a header file to use it (stdint.h). char is undefined as to whether it's signed or unsigned so if you care you have to put ``unsigned' in front of it which is a whole lot more effort.
There's no real good solution. I generally stick with uint8_t in libraries, but I think byte is best for sketches