C ++预处理器如何工作? [英] How does C++ preprocessor work?

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

问题描述

我正在阅读《 C ++ Primer》第5版,我读到预处理器是在C ++编译器之前运行的程序,并用适当的内容替换#include,#define和#ifdefs等,然后进行控制交给编译器。

I am reading the book "C++ Primer" 5th Edition and I read that the preprocessor is a program that runs before the C++ compiler and replaces the #include, #define and #ifdefs and others with the appropriate content and then transfer control over to the compiler.

但是我在cl.exe(Microsoft编译器)中遇到了一种方法,可以查看直接保存到文件中的预处理器输出。我做到了,当我打开预处理器输出文件时,我感到很惊讶,因为我没有找到我所期望的!

But I came across a way in cl.exe (Microsoft Compiler) to view the preprocessor output saved directly to file. I did it, and when I opened the preprocessor output file I was surprised because I did not find what I expected!

它们很大,并且包含看起来很模糊的代码!

They were totally big and contained what looked like obfuscated code!

请解释一下C ++的预处理器实际上是做什么的。

推荐答案

完全可以像处理C或C ++一样预处理Java。只需使用以下内容:

It is entirely possible to pre-process Java just like you do C or C++. Just use something like this:

gcc -E myjava.java > myjava.preprocesses.java

然后可以使用宏扩展, #if 等内容。当然,它确实具有缺点,那就是需要另外的工具进行编译。

Then you can use macro expansion, #if etc to your hearts content. Of course, it does have the drawback that there is a further tool needed for the compile.

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

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