Use Clang to convert C++ to C code

2019-03-21 17:31发布

I know that llvm can be used to convert c++ into c code. I was wondering if clang could do the same thing (seeing as clang was derived from llvm).

So can I use clang to convert c++ code into c code?

If you want to know why I want to do this here is my scenario:

PIC, which is a micro controller manufacturer, does not make c++ compilers, but does make c compilers for most of their products. I want to write in c++ and then as part of my build process, convert the c++ code into a temporary c file, which is then fed into the PIC compiler, and viola I have written c++ code for a PIC micro.

1条回答
走好不送
2楼-- · 2019-03-21 18:14

Clang can read C++ and emit LLVM IR. You seem to be aware that LLVM can read IR and emit C (from your own link: http://llvm.org/releases/3.1/docs/FAQ.html#translatecxx). So Clang cannot directly emit C, but it can emit LLVM IR which you then turn around and convert to C. Two steps, and Clang is one of them.

查看更多
登录 后发表回答