Use Clang to convert C++ to C code(使用 Clang 将 C++ 转换为 C 代码)
问题描述
我知道llvm可以用来把c++转成c代码.我想知道 clang 是否可以做同样的事情(看到 clang 是从 llvm 派生的).
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).
那么我可以使用clang将c++代码转换成c代码吗?
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 是一家微控制器制造商,不生产 c++ 编译器,但为他们的大多数产品生产 c 编译器.我想用 c++ 编写,然后作为构建过程的一部分,将 c++ 代码转换为临时 c 文件,然后将其输入 PIC 编译器,中提琴我已经为 PIC micro 编写了 c++ 代码.
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.
推荐答案
Clang 可以读取 C++ 并发出 LLVM IR.您似乎知道 LLVM 可以读取 IR 并发出 C(来自您自己的链接:http://llvm.org/releases/3.1/docs/FAQ.html#translatecxx).所以 Clang 不能直接发出 C,但它可以发出 LLVM IR,然后你转身转换为 C.两步,Clang 就是其中之一.
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.
这篇关于使用 Clang 将 C++ 转换为 C 代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 Clang 将 C++ 转换为 C 代码
基础教程推荐
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- CString 到 char* 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
