Is there a way of compiling C11 to C89?

こ雲淡風輕ζ 提交于 2019-12-21 03:35:40

问题


One of my (embedded) targets only has a C89 compiler.

I am working on a (hobby) project which targets multiple devices.

Is there a way of compiling (transpiling?) a C11 code base into C89?

(Otherwise I will have to code like it's 1989, literally.)


回答1:


No I don't think that it is possible for all of C11. C11 has features that simply not exist in C89 or C99: _Generic, _Atomic, _Thread, _Alignof, well defined sequenced before ordering, unnamed struct and union members ... These don't have counter parts in the older versions and would be really difficult to emulate.

For any of these features you would have to rely on extensions of your target compiler, so probably possible for some of the features for one given compiler. But it would be a nightmare to write such a tools that would have plain C89 as a generic target. You'd better implement a C11 compiler directly.




回答2:


As Carl Norum comments:

What's your target? Would it be hard to port clang/llvm?

This seems to be the promising approach.
It's not necessary to port your target, a port for C89 is enough.

So clang compiles your code to llvm and then llvm to c89 and then you get it.



来源:https://stackoverflow.com/questions/19121453/is-there-a-way-of-compiling-c11-to-c89

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