保持 Erlang 和 C 之间的定义同步
来自 http://www.erlang.org/doc/apps/erts/driver。 html:
/* Keep the following definitions in alignment with the
* defines in erl_pq_sync.erl
*/
#define DRV_CONNECT 'C'
#define DRV_DISCONNECT 'D'
#define DRV_SELECT 'S'
是否有任何简单的方法可以在 Erlang 和 C 源之间共享宏的值?
From http://www.erlang.org/doc/apps/erts/driver.html:
/* Keep the following definitions in alignment with the
* defines in erl_pq_sync.erl
*/
#define DRV_CONNECT 'C'
#define DRV_DISCONNECT 'D'
#define DRV_SELECT 'S'
Is there any simple way to share the values of macros between Erlang and C sources?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我对 Erlang 一无所知,但想必你不能只创建一个 .h 文件,其中只包含所需的定义并在两个地方 #include 它(或等效的)。
假设你不能做到这一点,我会考虑自动生成一个文件。
编辑:刚刚查看了 Erlang 文档,格式非常相似,但不完全相同。
Erlang 需要
-define(Const, Replacement)
C 需要
#define const replacement
所以我会编写一个包含 Erlang 语法的文本文件(仅用于这些定义),然后 执行一些操作,然后将其
#include
添加到我的 C 源代码中。作为 C 构建中的预构建步骤,我会在该文件的临时副本上
I know nothing about Erlang, but presumably you can't just create a .h file with just the required defines in and #include it (or equivalent) in both places.
Asuming you can't do this, I would look at auto generating a file for one from the other.
EDIT: Having just looked at the Erlang docs, the format is very similar but not quite the same.
Erlang needs
-define(Const, Replacement)
C needs
#define const replacement
So I would write a single text file which contained the Erlang syntax (for just these definitions) and then as a pre-build step in my C build I would do something along the lines of
on a temporary copy of that file, which I would then
#include
in my C source.您可以(尝试)在erlang中使用gcc的C预处理器,因为gcc有选项:
-E
stop after preprocessing stage-x language
(您可以设置一个给出正确的值)输出)-P
禁止输出#line
-C
保留注释(不要删除 /* */ 和 // )You may (try to) use C preprocessor of gcc in erlang, as gcc have options:
-E
stop after preprocessing stage-x language
(you may set one which gives correct output)-P
inhibit output of#line
-C
keep comments (do not remove /* */ and // )一种非常动态的方法是在 C 中保留一个表,该表可以通过使用具有
char *name
-> 的 # 的宏轻松生成。价值观。然后用它在开始时向 erlang 发送一个表。
使用此表将其开头发送到 erlang,将其解码为元组列表并使用它进行查找。
One very dynamic way is to keep a table in C wich can easily generated by macros using # that have
char *name
-> values.Then use this to send erlang a table at the beginning.
Use this table to send it at the beginning to erlang, decode it there into a tuple list and use this to look up.