On Fri, Apr 22, 2016 at 01:53:11PM -0400, Steven W. Scott wrote:
> Bogus mayhaps. Whatever the issue, it's been there a while because previous
> versions fail as well. Having spent the first 25-30 years of my career in
> assembly language, I completely understand "optimization" by a compiler;
> it's a method used to attempt compensation for inherent inefficiencies in
> the language and/or compiler itself. The very existence of something like
> Valgrind (which I am enjoying very much, thanks for the tip guys!) speaks
> much about the language, IMHO.
I would object that valgrind has nothing to do with C, in principle :)
It can be used with any executable, and is normally pretty accurate,
especially in detecting memory-related problems (e.g., overruns) which
are otherwise quite hard to find.
[cut]
>
> But I digress. I've always considered compiler "optimizations" to be a form
> of witchcraft and thus, suspect. The code is fairly complex, multi-threaded
Luckily, optimisationsa are not based on witchcraft, but rather on
maths :) If the hypothesis made by the specific optimisation procedure
are met (and this is true for single-threaded standard-compliant C/C++
code, as correctly pointed out by Adam) then the result of an
optimisation is alway a code that is *functionally equivalent* to the
unoptimised code. This means that if I give you the two executables
(one optimised and one not optimised) you will not be able by any
means to detect any difference in their behaviour, i.e. in the output
they provide for the same sequence of inputs, exept for (hopefully)
the time they need to complete their task.
> SMP capable, and as it performs hw emulation, also traps faults by
> necessity, which severely increases the PITA factor in debugging/diagnosis.
> The lazy programmer in me was hoping to find a "doh, you're an idiot" or
> stupid oversight I had missed from the folks here, but alas, like the auto
> problem I know will be a bear to fix, I must pull out the ramps and open
> the hood.
If your program uses multiple threads, then you should probably
refrain from using -O3 altogether, since some of those optimisations
are likely to create problems, as explained for instance here:
http://stackoverflow.com/questions/14850593/when-can-i-confidently-compile-program-with-o3/14853616#14853616
My2Cents
KatolaZ
--
[ Enzo Nicosia aka KatolaZ --- GLUG Catania -- Freaknet Medialab ]
[ me [at] katolaz.homeunix.net --
http://katolaz.homeunix.net -- ]
[ GNU/Linux User:#325780/ICQ UIN: #258332181/GPG key ID 0B5F062F ]
[ Fingerprint: 8E59 D6AA 445E FDB4 A153 3D5A 5F20 B3AE 0B5F 062F ]