vogelchr / radioclkd2

Quick and dirty fork of http://www.jonatkins.com/page/software/radioclkd2 adding Linux GPIO pin support.
19 stars 7 forks source link

Fix clkPulseLength() incorrect behaviour with GCC "-O2" optimization flag #11

Closed jorgedsmatias closed 2 years ago

jorgedsmatias commented 2 years ago

When compiling code with gcc 10.2.1 on a Raspberry Pi 3 running Debian Bullseye (amrhf / 32bit) I have noticed that function clkPulseLength() add an incorrect behaviour identifying clock pulse length. I have found this would happen because -O2 gcc compiler option. To avoid compiler the compiler optimization that was discarding variable initializations in switch() scope, I have modified the code so it wouldn't skip it.

vogelchr commented 2 years ago

Thanks alot for your contribution. I'm no longer using this code myself, but I'll happily apply you patch, it looks fine for me.