What are the data sizes of all the primitive datatypes on a Metro M4 Express SAMD51 C++ implementation? In some C++ implementations, int has 16 bits and in other implementations it has 32 bits. Is

  • 1
    It depends on compiler's data model for target processor. But I'd rather use int16_t/int32_t instead. It's much better for portability.
    – KIIV
    Commented Oct 28, 2019 at 19:40

2 Answers 2


And that is the only difference in fundamental type sizes. On 8-bit Arduinos int is 16 bit and on 32-bit int is 32 bit.

  • short is 16 bit
  • long is 32 bit
  • long long is 64 bit



Here is a sketch to quickly find out unsigned maximum values on any architecture and deduce the bit width from them (I had to use sprintf, because Serial.println(unsigned long long) did not work on my Due):

#include <limits.h>

#define sprintfln(args...) { char _qsx6_[200]; snprintf(_qsx6_, 200, args); Serial.println(_qsx6_); } // _qsx6_ may collide with local var

void setup()

    unsigned char  uc = 0; uc=~uc; Serial.println(uc);
    unsigned short us = 0; us=~us; Serial.println(us);
    unsigned int   ui = 0; ui=~ui; Serial.println(ui);
    unsigned long  ul = 0UL; ul=~ul; Serial.println(ul);
    unsigned long long ull = 0ULL; ull=~ull; // doesn't work: Serial.println(~ull);
    sprintfln("char:%u short:%u int:%u long:%lu long long:%llu", uc, us, ui, ul, ull);
    sprintfln("char:%u short:%u int:%u long:%lu long long:%llu", UCHAR_MAX, USHRT_MAX, UINT_MAX, ULONG_MAX, ULLONG_MAX);
    sprintfln("char:%u short:%u int:%u long:%u long long:%u", sizeof(uc), sizeof(us), sizeof(ui), sizeof(ul), sizeof(ull));
    sprintfln("pointer:%u", sizeof(&uc));

On Arduino Due this gives (I expect it to be the same on SAMD51):

long long:18446744073709551615
char:1 short:2 int:4 long:4 long long:8

Usually you could include "limits.h", but it seems that unsigned long long is missing (at least on Due). Hmmm, I didn't expect int and long to be the same, good to know.

  • 1. Note that unsigned int ui = -1; is a valid way to set an unsigned number to it's maximum value. 2. sizeof(int) may be more convenient. 3. int and long are both 32 bits on most 32-bit environments, and even on 64-bit Windows. 4. It would be cool to have also the size of pointers. Commented Jul 30, 2021 at 9:14
  • Oh, forgot about sizeof() which works on pointers, too. To your suggestion (1) I would comment that 'unsigned long long x = -1LL' is strange style with type conversion and its up to the compiler to do the right thing. I would not do that.
    – cat
    Commented Aug 7, 2021 at 4:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.