Code: Select all
Have a look at this Microsoft employee's answer. I think that will remove your confusion.
http://social.microsoft.com/Forums/is/windowshpcacademic/thread/65a1fe05-9c1d-48bf-bd40-148e6b3da9f1
Most lower bits are written in assembly, the bit on top of it must be raw C (compiled using the C++ compiler anyway ;) ) and the code on top of it can be anything like C++, C#, etc...
that project manager of HPC team told there that nothing about compiling C code with C++ compiler there.
where he told that thing? He told we use both C and C++ in writing windows operating system.
if you ever write a operating system using C then you probably know why we use C, because C name managing
or name decoration is very simple. But C++ name mangling is little bit complicated(because it supports
overloading, let me remind you C does not support overfloading, you probablly know this already anyway).
because of that simplicity , we could use them very easily in linker editor scripts.And inside call
C functions inside assembly.So lower parts and even the bootcode, developers prefer C instead of C++.
But it doesn't said you can't do the same thing using C++ anyway.
I'm not interested to go in to much details on gcc C compiler as it is not the only C compiler in the world. I only use it to compile my apps in Linux, nothing more than that. Besides gcc is a compiler collection that provides few compilers bundled together. So within the bundle, it has named the structure as Front, Middle and Back that I have no interest to learn since its kind of an internal naming for them. But I would have gone in to lexical analyser stage on the C compiler to check whether how it distinguish between C and CPP syntax.
So did you see same scanner is used for both C++ and C, dude font end means scanner+parser, and lexical
analyzer don't deal with the syntax , it just torkanize the things in source file into tokens.For a example , '
if we input this file ,
the lexer will out like this.bellow V
Code: Select all
<keyword,int>
<identifier,main>
<(>
<)>
<{>
<keyword,return>
<literal,int,1>
<;>
<EOF>
it does not parse and generate the IR (intermediate representation at all) to the backed.
Simply in modern compiler implementations parser is calling the scanner(get_next_lex() ) or
something like that. If the gcc codebase is soo complicated then I suggeset you to
read the source code of the example compiler implementation of Tiny C in Compiler Construction
Principles and Practice book by Keneth C. Louden, you could find it in the book appendix.
I have attached the sources of both C++ lexer and C lexer bellow.
C++ lexer file is just "lex.c" and C lexer is "c-lex.c". Please take the time and go through
those.
can you see the differences and similarities of each other?
could you?
And there are two parser scripts for parser generator too. They are different in C vs C++ too.
So their font-end are very very different. I do suggest you to go through both of them carefully,
if you felt complicated go back to the Compiler Construction Principles and Practice by
Kenneth C. Louden book and read the appendix example Tiny C implementation and come back to
read this.
and neo could you please put these four posts in another thread to keep our robot.lk managed !
--Thanks in advance--