Hi all, I'm new to this forum so I don't know if this already came up.
code:
void loop()
{
byte c = 1, d = 1;
char buf[0x100];
Serial.println("------------------");
for(int i=0;i<0x200;i++) {
sprintf(buf,"%5d,%5d,%5d,%5d",sizeof(c), c, sizeof(d), d);
Serial.println(buf);
c*=2;
d++;
}
}
output on console:
------------------
1, 1, 1, 1
1, 2, 1, 2
1, 4, 1, 3
...
1, 64, 1, 7
1, -128, 1, 8
1, 0, 1, 9
1, 0, 1, 10
....
1, 0, 1, 253
1, 0, 1, 254
1, 0, 1, 255
1, 0, 1, 256
1, 0, 1, 257
1, 0, 1, 258
1, 0, 1, 259
I'm a bit puzzeld about sizeof(d) returning 1 but apperantly beeing capable counting above 8-bit limit, if using postfix increment.
Maybe someone can explain the magic behind?
Thanks,
chi