多遍C预处理器 [英] Multi-pass C preprocessor

查看:82
本文介绍了多遍C预处理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C 预处理器多次应用于同一代码库是否很明智(特别是顺序两次)?

Is it remotely sane to apply the C preprocessor to the same codebase multiple times (specifically, twice in sequence?)

例如,其声明如下:

##define DECLARE(FILE) # define DECLARATIONS \
                       #   include FILE \
                       # undef DECLARATIONS

您以前见过这样的习语吗?如果是这样,什么代码库?你可以链接吗?编译这样的项目将遵循哪种模式?是否可以按原样制作CPP来执行此操作,还是我需要编写一个元预处理器来在处理双哈希声明时隐藏单哈希声明,等等?

Have you ever seen such an idiom before? If so, what codebase? Can you link it? What sort of patterns would be followed to compile a project doing something like this? Can the CPP as it stands be made to do this, or do I need to write a meta-preprocessor to "hide" the single-hash declarations while processing the double-hash declarations, and so on?

推荐答案

我认为当您需要多次CPP传递时,您可能需要考虑使用m4或其他一些复杂的宏系统/代码生成器。我认为很难做到所需的事情,并且由于无论如何都要更改构建过程,因此请查看其他模板或宏系统。

I think when you need multiple CPP passes, you might want to consider m4 or some other sophisticated macro system/code generator. I think it will be hard to do what you want, and since you are going to be changing your build process for this anyway, look at other templating or macro systems.

这篇关于多遍C预处理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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