QuickESPNow icon indicating copy to clipboard operation
QuickESPNow copied to clipboard

Remove compiler warnings for ESP32

Open blazoncek opened this issue 1 year ago • 3 comments

Using if (espnowTxTask_cb) will always yield true as the function exists.

Also changed counter type in for loops from uint8_t to int to optimise for size and speed.

blazoncek avatar Sep 09 '24 14:09 blazoncek

"Also changed counter type in for loops from uint8_t to int to optimise for size and speed." I was wondering why you did this. We have recently changed our commercial code from INT to uint8_t or uint16_t as not all compilers compile using the same space. Arduino will compile one way and other compilers compile another. We had a major bug as we assumed our compiler Take for example a struct message.

uint16_t a; uint8_t b; uint8_t c; uint8_t d;

is not the same as

double a; int b; int c; int d;

we lost days and days on this bug

svdrummer avatar Sep 11 '24 09:09 svdrummer

int and unsigned will compile to native size (almost always) while providing (at minimum) 16 bit resolution.

Their use in these for() loops has no effect on portability/compatibility but has a great effect on code size and speed. Tested in WLED project.

When you use uint8_t (unsigned char) you are telling compiler that you want 8 bits, so it will add instructions to insure the output will be 8 bit (including sign expansion if necessary). No such case is needed when using such counter as an index to an array.

blazoncek avatar Sep 11 '24 09:09 blazoncek

We had a major bug as we assumed our compiler

Assumption was the cause of bug, not compiler. Compilers behave on a number of rules. Assumptions do not.

blazoncek avatar Sep 11 '24 09:09 blazoncek