Interesting. But could you elucidate why a global char is 2 bytes in c++ to begin with and why it is not the same in c.
thanks; Lawal.O --- In [email protected], "peternilsson42" <peternilsso...@...> wrote: > > Sanjeev Gopinath <sanjeevsince90@> wrote: > > > > Hello all, > > I've some series of questions...! > > * Is there any difference when a C program runs in a C++ > > compiler? > > There's no such thing as a C program to a C++ compiler. > > The following is a C program. Tell me which language your > C++ compiler thinks it is... > > #include <stdio.h> > > char foobar; > > int main() > { > struct foobar { char a[2]; }; > > if (sizeof(foobar) == sizeof(struct foobar)) > puts("C++ compiler."); > else > puts("C compiler."); > } > > > (I mean the approaches taken internally by the C++ compiler) > > A C++ compiler will, by definition compile C++ programs, whatever > the source code author's notion of which language it was written > in. > > These days, C and C++ compilers tend to be bundled together. > Modern compilers (e.g. GNU) will actually translate the source > language into an intermediate language anyway, thus using the > same optimisors and assemblers for both. > > But there have been systems where C++ calling conventions are > different to C calling conventions. There are also subtle > differences in the languages which mean that a C++ compiler > must treat the same line of code differently to a C compiler. > > > * Will the C++ compiler understand it as a C program? > > No more than a COBOL or FORTRAN compiler will understand it > as a C program. > > > If so, how does it differentiate? > > It doesn't. Some command line 'compilers' are really wrappers, > detecting the file extension and passing the source to the > appropriate 'real' compiler. The real compilers however > generally only understand one language. > > > * Will there be any storage difference between a C and C++ > > compiler? > > Storage difference? > > C++ implementations tend to be much larger than C ones because > the language is considerably more complex, and C++ has a much > larger standard library. > > -- > Peter >
