宏和多行注释 [英] Macros and multi-line comments

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

问题描述

我需要在一组宏中包含多行注释,以便其中一个宏启动注释块,另一个宏结束注释块,如下所示:

I need to have multi-line comments within a group of macros so that one of the macros initiates a comment block and another concludes it, like this:

#define C_BEGIN /*
#define C_END */
... other macros

$

推荐答案

不能做以下推理。让我们假设可能。

You can't do it for the following reasoning. Let's assume it is possible.

因此,您创建了一个用 / * 替换 / 。那么会发生什么呢?首先,从代码中删除注释。之后,预处理器将使用注释替换您的宏。之后,编译器会窒息:它不知道如何处理 / * * / ,因为它根本不会面临这样的事情:在编译之前总是删除注释,所以它甚至不知道注释是什么。它可能会认为它是一个除法,其次是乘法。

So you created a macro that replaces itself with /*, and another for */. What happens then? First, the comments are removed from the code. After that, the preprocessor replaces your macros with the comments. After that, the compiler will choke: it doesn't know what to do with /* and */ because it simply never faces such things: the comments are always delete before the compilation, so it doesn't even know what a "comment" is. It will probably think it's a division followed by multiplication.

所以我们的假设是错误的,你不能这样做。

So our assumption is wrong and you can't do it.

这篇关于宏和多行注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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