Thread: Compiler in C?

  1. #16
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by laserlight View Post
    That would not be necessary at all. Remember, we are talking about what can be done, not what is typically done.
    hmmm. okay. So you are saying the process of compiling the compiler takes care of this apparent paradox?

    This sounds kind of like baking rye or sourdough, where you need some small piece of already made dough as an ingredient. I guess, as matsp says, the "primal compiler" was in asm...
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  2. #17
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by MK27
    So you are saying the process of compiling the compiler takes care of this apparent paradox?
    Yes.

    As a side note, you might want to read Ken Thompson's Reflections on Trusting Trust.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #18
    Making mistakes
    Join Date
    Dec 2008
    Posts
    476
    Some compilers generate asm and assemble it then. I forgot that that didn't count. And I think, the very first C compiler was the one for Unix and written in assembler. Right?

  4. #19
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by laserlight View Post
    As a side note, you might want to read Ken Thompson's Reflections on Trusting Trust.
    Neat. But:
    We install this binary as the official C. We can now remove the bugs from the source of the compiler and the new binary will reinsert the bugs whenever it is compiled. Of course, the login command will remain bugged with no trace in source anywhere.
    Would that mean if you rebuilt the compiler, using the corrected (unbugged) source, and the (only available) bugged, pre-built compiler, that the new compiler would recognize that it is being re-built and insert this "Trojan Horse" code?

    I guess so...
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  5. #20
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by MK27
    Would that mean if you rebuilt the compiler, using the corrected (unbugged) source, and the (only available) bugged, pre-built compiler, that the new compiler would recognize that it is being re-built and insert this "Trojan Horse" code?
    Yes.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #21
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by MK27 View Post
    But surely, sir, there is a ton of __inline asm__ in there?
    Not at all. I would be very surprised if there is more than a few lines of inline assembler in gcc (if any). It makes the compiler less portable for one thing (and although a compiler compiling for a certain target obviously needs to know the machine code of the target system, but that's not to say that you don't want a x86 compiler to work from a Sparc system, for example - if the compiler for x86 has x86 assembler in it, then it would not compile on a Sparc system.

    Most of what compilers do is a load of string handling, binary trees, hash-tables and such.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #22
    Registered User
    Join Date
    May 2009
    Posts
    12
    Hey could someone give me an example of C code writing a .c file and using TCC to compile it, then perhaps run it?

    thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiler Paths...
    By Cobra in forum C++ Programming
    Replies: 5
    Last Post: 09-26-2006, 04:04 AM
  2. C Compiler and stuff
    By pal1ndr0me in forum C Programming
    Replies: 10
    Last Post: 07-21-2006, 11:07 AM
  3. I can't get this new compiler to work.
    By Loduwijk in forum C++ Programming
    Replies: 7
    Last Post: 03-29-2006, 06:42 AM
  4. how to call a compiler?
    By castlelight in forum C Programming
    Replies: 3
    Last Post: 11-22-2005, 11:28 AM
  5. Bad code or bad compiler?
    By musayume in forum C Programming
    Replies: 3
    Last Post: 10-22-2001, 09:08 PM