2

Possible Duplicate:
Code convert from C++ to C

Two months ago, my instructor have asked one question, I have searched to looking for answer but I could not find it.

question :

   From c++ code, how can one  generate c code just using console ( with g++ ) .

How can I do this ?

Community
  • 1
  • 1

2 Answers2

2

g++ compiles C++ directly to machine code, it does not first compile to C then compile that.

There may be some compilers that compile to C code first. I do not know of any if you really need the code. It is not the most efficient way to do it though.

I think that is what your instructor was trying to ask you, i.e. if there is a compiler switch to generate C code.

Is there any particular reason why you need to generate C code. Creating a C interface can be useful and there are ways to do this.

CashCow
  • 30,981
  • 5
  • 61
  • 92
0

I'm far from a GNU expert, but I belive the compiler option would be -std=C89, to enforce compilation to follow the C90 version of the C standard (equivalent to old "ANSI C" which was released in 89, hence the C89), or -std=C99 for the C99 version of the standard.

Lundin
  • 195,001
  • 40
  • 254
  • 396
  • Sure it would, it would give you a syntax error. If you used C++ unique features, then of course you wouldn't be able to compile it in C. – Lundin Jan 27 '11 at 11:04