将C预处理程序用于C以外的语言 [英] Using the C Preprocessor for languages other than C

查看:44
本文介绍了将C预处理程序用于C以外的语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C预处理器的Wikipedia条目指出:

The Wikipedia entry for the C Preprocessor states:


预处理器
指令的语言与 C 的语法
无关,因此 C 预处理器也可以单独使用
来处理其他
类型的文件。

The language of preprocessor directives is agnostic to the grammar of C, so the C preprocessor can also be used independently to process other types of files.

这怎么可能完成了吗有示例或技巧吗?

How can this be done? Any examples or techniques?

编辑:是的,我对宏处理最感兴趣。即使它不建议使用或不可维护,了解可能的方法仍然有用。

Yes, I'm mostly interested in macro processing. Even though it's probably not advisable or maintainable it would still be useful to know what's possible.

推荐答案

您可以直接致电CPP:

You can call CPP directly:

cpp <file>

而不是通过gcc调用它:

Rather than calling it through gcc:

gcc -E filename

但是请注意,如上所述在同一Wikipedia文章中,C预处理程序的语言并没有真正适合通用用途:

Do note however that, as mentioned in the same Wikipedia article, C preprocessor's language is not really equipped for general-purpose use:


但是,因为C预处理程序没有其他
预处理器的功能,例如递归宏,根据
进行选择性扩展以进行报价,条件中的字符串评估以及Turing
完整性,与更通用的宏$相比,它非常有限b $ b处理器,例如m4。

However, since the C preprocessor does not have features of some other preprocessors, such as recursive macros, selective expansion according to quoting, string evaluation in conditionals, and Turing completeness, it is very limited in comparison to a more general macro processor such as m4.

您是否考虑过使用更灵活的宏处理语言,例如上述m4?

Have you considered dabbling with a more flexible macro processing language, like the aforementioned m4 for instance?

这篇关于将C预处理程序用于C以外的语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆