Hi all --
New to Arduino platform. I have an Arduino Uno. I am a retired software and database developer, so I know that every platform and every language has its quirks. I'm wondering if that's what I'm observing. So I just did this simple program to see what actually happened with variables of different sizes as I was observing results that didn't make sense. Here's the program, followed by the results. Can anyone explain to me what's going on (or not going on)? The last one, the pulseIn() vs pulseInLong() both seem to return a long, so why have both?
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
}
void loop() {
uint64_t u64;
uint32_t u32;
uint16_t u16;
uint8_t u8;
u64 = (uint64_t)0xFAFAFAFAFAFAFAFALL;
u32 = (uint32_t)0xEBEBEBEBL;
u16 = (uint16_t)0xA7A7;
u8 = (uint8_t)0xD;
char buffer[100];
sprintf(buffer, "u64: %016X U64 size: %u", u64, (uint16_t)sizeof(u64));
Serial.println(buffer);
sprintf(buffer, "u32: %08X U32 size: %u", u32, (uint16_t)sizeof(u32));
Serial.println(buffer);
sprintf(buffer, "u16: %04X U16 size: %u", u16, (uint16_t)sizeof(u16));
Serial.println(buffer);
sprintf(buffer, "u8: %02X U8 size: %u", u8, (uint16_t)sizeof(u8));
Serial.println(buffer);
int pulseReturn;
pulseReturn = sizeof( pulseIn(2, HIGH, 1000));
sprintf(buffer, "Size of pulseIn(): %u", pulseReturn);
Serial.println(buffer);
pulseReturn = sizeof( pulseInLong(2, HIGH, 1000));
sprintf(buffer, "Size of pulseInLong(): %u", pulseReturn);
Serial.println(buffer);
Serial.flush();
exit(0);
}
Results:
u64: 000000000000FAFA U64 size: 64250
u32: 0000EBEB U32 size: 60395
u16: A7A7 U16 size: 2
u8: 0D U8 size: 1
Size of pulseIn(): 4
Size of pulseInLong(): 4