自动生成C code从头 [英] Automatically Generate C Code From Header
问题描述
我要生成的头文件中定义的过程空实现。理想的情况下,他们应该返回NULL指针为0整数等,并在一个理想的世界,同时打印到stderr哪个函数被调用。
I want to generate empty implementations of procedures defined in a header file. Ideally they should return NULL for pointers, 0 for integers, etc, and, in an ideal world, also print to stderr which function was called.
有这样做的动机是实现能够适应复杂的,现有的API(头文件)到另一个库的子集的包装的需要。只需要在API中的程序有少数被委派,但目前还不清楚哪些。所以,我希望用迭代的方法,在这里我对运行这个自动生成的包装,看到什么叫,实施与授权,并重复。
The motivation for this is the need to implement a wrapper that adapts a subset of a complex, existing API (the header file) to another library. Only a small number of the procedures in the API need to be delegated, but it's not clear which ones. So I hope to use an iterative approach, where I run against this auto-generated wrapper, see what is called, implement that with delegation, and repeat.
我已经看到<一个href=\"http://stackoverflow.com/questions/1404614/automatically-generate-c-file-from-header\">Automatically生成头C ++文件?但答案似乎是C ++特有的。
I've see Automatically generate C++ file from header? but the answers appear to be C++ specific.
因此,对于那些需要简单来说拼写出了问题,我怎么能这样自动给出的头文件实现的一代人?我想preFER现有的工具 - 使用pycparser一个简单的解决方案,我目前最好的猜测
So, for people that need the question spelled out in simple terms, how can I automate the generation of such an implementation given the header file? I would prefer an existing tool - my current best guess at a simple solution is using pycparser.
更新谢谢你们。这两个很好的答案。也张贴我目前的黑客。
update Thanks guys. Both good answers. Also posted my current hack.
推荐答案
UML建模工具能够在所选择的语言生成默认的实现。一般也有导入源$ C $ C(含C头文件)支持。您可以尝试导入你的头和生成从中源$ C $ C。我个人有企业架构师体验,它支持这两种操作。
UML modeling tools are capable of generating default implementation in the language of choice. Generally there is also a support for importing source code (including C headers). You can try to import your headers and generate source code from them. I personally have experience with Enterprise Architect and it supports both of these operations.
这篇关于自动生成C code从头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!