1

I want to see corresponding C code for a cpp file. Is there any option in g++ compiler to get the intermediate C code on compiling the C++ classes??

5
  • 3
    There is no such a thing (no intermediate c code for c++). Commented May 22, 2015 at 17:54
  • I remember I have seen it somewhere. It was not exactly a C file but there were all global functions in it. No classes or member functions Commented May 22, 2015 at 17:57
  • What C++ compiler are you using? Commented May 22, 2015 at 18:06
  • @rici As tagged probably. Commented May 22, 2015 at 18:21
  • I tried with -fdump-tree-all option and the .gimple file was close to C code Commented Jun 30, 2015 at 16:34

1 Answer 1

3

"I want to see corresponding C code for a cpp file."

There's no such thing like a corresponding C code for a .cpp file (At least not with as tagged in your question). C and C++ are quite different languages, and it's hard (and not necessary) to transform all of modern C++ features to C code.

There was intermediate c code produced by very early implementations of the c++ compiler IIRC.

Nowadays c++ compilers produce either assembly code for the specified machine directly, or provide intermediate code using a backend. I can't find an option to see intermediary produced c code (probably since the compiler doesn't work this way).

The only options I'm aware of are -S to produce intermediary assembly code and -E that results in files after the CPP preprocessor was applied.

The LLVM project seems to provide a backend, that translates anything from the AST parsed with the frontend (e.g. clang fo c++) to c language.

Well, I didn't try any of these linked search results myself.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.