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 代码


基础教程推荐
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 从 std::cin 读取密码 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01