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??
-
3There is no such a thing (no intermediate c code for c++).Eugene Sh.– Eugene Sh.2015-05-22 17:54:28 +00:00Commented 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 functionsUtsav– Utsav2015-05-22 17:57:55 +00:00Commented May 22, 2015 at 17:57
-
What C++ compiler are you using?rici– rici2015-05-22 18:06:01 +00:00Commented May 22, 2015 at 18:06
-
@rici As tagged probably.πάντα ῥεῖ– πάντα ῥεῖ2015-05-22 18:21:22 +00:00Commented May 22, 2015 at 18:21
-
I tried with -fdump-tree-all option and the .gimple file was close to C codeUtsav– Utsav2015-06-30 16:34:18 +00:00Commented Jun 30, 2015 at 16:34
1 Answer
"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 g++ 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.