Use Clang to convert C++ to C code

对着背影说爱祢 提交于 2019-12-21 02:36:13

问题


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:


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.



来源:https://stackoverflow.com/questions/37082302/use-clang-to-convert-c-to-c-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!