Chris Hills said:
That is incorrect. There are compilers I know that will compile for
size or speed. They generate different code depending on the flags.
Thus whilst the external functionality of both is the same the
internal behaviour is different. In some cases if you want faster code
the executable is larger because it will unwrap some calls and
loops. Register and memory usage is different.
My point is that the code generated by a compiler is not (or should
not be) affected by any optimizations performed by the compiler used
to compile the compiler. The compiler itself may run more quickly
and/or use less memory, but it will generate the same code.
Let me try to make the point more clearly. Suppose I have a Pascal
compiler written in C. For simplicity, assume the Pascal compiler
source is a single C source file, "pas.c". Suppose I have a Pascal
program source file "foo.p".
(1) gcc -O0 pas.c -o pas_slow
(2) ./pas_slow foo.p -o foo0
(3) ./foo0
(4) gcc -O3 pas.c -o pas_fast
(5) ./pas_fast foo.p -o foo1
(6) ./foo1
Line 4 will likely take longer to execute than line 1, because gcc is
doing extra work. Line 5 will likely execute more quickly than line
2, because in line 5 I'm executing optimized code. But the "pas_slow"
and "pas_fast" programs (both Pascal compilers) should behave
identically (apart from their speed), which means they should produce
essentially identical code from the same Pascal source, and lines 3
and 6 should take the same time to execute (ignoring random
variations).
If pas_slow and pas_fast behave differently, in the sense of producing
different output, then the optimizer is broken, or possibly pas.c
depends on undefined behavior.
Ps Keith I hadn't forgotten I owe you an answer to the other post on
the Safe C lib. I have to dig out the file and read it with some
thought Things are VERY hectic here including builders removing
walls. (Everything is covered in dust or in boxes or in store)
Can you remind me which thread this is about (the subject header will
do)? Thanks.