I should also have said that the compiler is even allowed to change the order of execution of expressions and statements when the order is defined by the Standard so long as the resulting state is the same as if it were executed in the defined order. This has lead to some very nasty concurrency bugs in threaded code, for example the so called "double checked lock" used in quite a lot of C++ code to initialize singleton object instances.
On 17/10/2014 17:54, Bill Somerville wrote: > On 17/10/2014 16:29, Joe Taylor wrote: > > Hi Joe, >> I have spent 1.5 days trying to understand why kvasd[.exe], the >> Koetter-Vardy algebraic soft-decision decoder, compiled correctly with >> versions 4.6.1 and 4.6.3 of gcc and gfortran, but fails with versions >> 4.8.1 and 4.8.2. >> >> With the code as it has been for some years, the build appears >> successful but the program fails to execute correctly. >> >> After scratching my head with long gcc/gdb debugging sessions, I >> discovered that the combination clang (v3.5) + gfortran 4.8.2 worked >> perfectly. More importantly, clang identified the problem. >> >> Ralf Koetter's code used a number of constructions like the following: >> >> for (y = m2-1-x; y; ) d[y--] = p[y]; >> >> The clang compiler flagged these with warnings like this: >> >> warning: unsequenced modification and access to 'y' > Yes, that is undefined behaviour. >> From context it's clear that the intended ordering is to decrement y >> after the copy operation. An unambiguous way to write the statement is thus >> >> for (y = m2-1-x; y; y--) d[y] = p[y]; >> >> Somewhere between gcc 4.6.3 and gcc 4.8.1, the GNU folks did something >> that changed the ordering of copy and decrement in the original statement. > Probably more aggressive optimization, compilers are free to reorder > expressions where the Standard doesn't define a strict sequencing. >> Anyway, the good news is that I fixed all the ambiguous "unsequenced >> modifications", and the code now executes correctly with all the >> compilers I've been testing. >> >> Three cheers for clang!!! >> >> -- Joe, K1JT > 73 > Bill > G4WJS. > > ------------------------------------------------------------------------------ > Comprehensive Server Monitoring with Site24x7. > Monitor 10 servers for $9/Month. > Get alerted through email, SMS, voice calls or mobile push notifications. > Take corrective actions from your mobile device. > http://p.sf.net/sfu/Zoho > _______________________________________________ > wsjt-devel mailing list > wsjt-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/wsjt-devel ------------------------------------------------------------------------------ Comprehensive Server Monitoring with Site24x7. Monitor 10 servers for $9/Month. Get alerted through email, SMS, voice calls or mobile push notifications. Take corrective actions from your mobile device. http://p.sf.net/sfu/Zoho _______________________________________________ wsjt-devel mailing list wsjt-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wsjt-devel