void loop (void) { ; }
void setup (void) {
int x;
Serial.begin(115200);
x = sizeof(unsigned long long);
Serial.print("Size of unsigned long long is ");
Serial.println(x);
x = sizeof(uint64_t);
Serial.print("Size of uint64_t is ");
Serial.println(x);
// unsigned long long y = 0xFFFFFFFFFFFFFFFF;
// uint64_t z = 0xFFFFFFFFFFFFFFFF;
}
Running it yields:
Size of unsigned long long is 8
Size of uint64_t is 8
Uncommenting the two commented lines, however, generates an error:
test:17: error: integer constant is too large for ‘long’ type
test:18: error: integer constant is too large for ‘long’ type
Anyone know:
(1) Why this happens ...and
(2) If it can be fixed?
Krupski:
Now the question is... WHY do I have to use that?
The compiler infers the type of the literal constant from its value. I believe the rule for integer values is that if the value will fit in an int the type is int, otherwise the type is long int. If you want it to be any other type, for example long long int, then you have to tell the compiler what type to use.