Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C compiler compiling

Name: Anonymous 2007-10-08 20:02

One of the students bought this question up in a tutorial and this anon thought it would be interesting if it was discussed with his other aliases on 4ch.

The question this anon was approached with was:
If one day a keen programmer (with too much free time) decided to write a new C compiler in C, and succeeded.

Assuming that the following holds:
-It is actually possible to write a C compiler in C for the architecture & build environment
-The series of operations that we are about to conduct are all isolated on the original build environment and CPU architecture
-All of the C language aspects employed by the source code of the new compiler are implemented properly in the source code.
-The code is magically debugged and will fully function to it's designed functionality contracts.
-The new compiler has optimization algorithms that will fully preserve functionality of the inputed code.
-No inappropriate usage of the C language was employed in the source code (such as language hacks)

Now the programmer compiles the written source code in an industry standard C compiler, producing a derived C compiler. If the source code is then repetitively fed into the derived compilers, what would happen?
1) The machine code size will converge to a resultant product that will be in full equilibrium, and will be much more optimized than the predecessor compilers (excluding the original product that is not manufactured by this source code)
2) The machine code size will diverge however maintains functionality, efficiency however may vary.
3) The machine code size will diverge, and functionality will not be maintained thus eventually leading to an error and failing to create additional derived compilers.
4) Something else? Explain.

My answer was 2. What do you think?

Name: Anonymous 2007-10-09 3:08

I've also written a compiler before, albeit a simple one.

>>4 basically got it

>>5
given the same input, a program will ALWAYS produce the same output

the reason that in your case the output is different is because the two binary are different, hence the compilation result is different

it is like taking a compiler, then the same one but optimised, and compile the same source code, if they are both very efficient, then they should produce the same machine code, but that rarely happens unless the writer designed the architecture or are extremely familiar with it him/herself.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List