“宏注释嵌入到注释中"的含义是什么?在mcpp中意味着什么? [英] What does "macro annotations embedding in comments" mean in mcpp?

查看:58
本文介绍了“宏注释嵌入到注释中"的含义是什么?在mcpp中意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

mcpp.exe --help

Options available with only -@std (default) option:
-@compat    Expand recursive macro more than Standard.
-3          Enable trigraphs.
-K          **Output macro annotations embedding in comments.**

那么,注释中的宏注释"是什么意思?

So, what does 'macro annotation in comments' mean?

http://mcpp.sourceforge.net/

推荐答案

来自SourceForge的mcpp-summary-272.pdf文件(有问题的链接):

From the mcpp-summary-272.pdf file available at SourceForge (link in question):

也mcpp具有输出宏信息的模式嵌入评论中.此模式可让您了解宏调用及其在源上的位置预处理输出中的文件.

Also mcpp has a mode to output macro informations embedded in comments. This mode allows you to know macro calls and their locations on source file from preprocessed output.

因此,它留下了注释,以标识扩展的宏,以便您可以分辨出哪个源来自哪个宏.

So, it leaves behind comments identifying the macros expanded, so that you can tell which source came from which macro.

#include <assert.h>
int main(int argc, char **argv)
{
    assert(argc != 0 && argv != 0);
    return 0;
}

mcpp x.c

#line 1 "/Users/jleffler/src/cmd/x.c"
#line 1 "/usr/include/assert.h"
#line 42 "/usr/include/assert.h"
#line 1 "/usr/include/sys/cdefs.h"
#line 417 "/usr/include/sys/cdefs.h"
#line 1 "/usr/include/sys/_symbol_aliasing.h"
#line 418 "/usr/include/sys/cdefs.h"
#line 494 "/usr/include/sys/cdefs.h"
#line 1 "/usr/include/sys/_posix_availability.h"
#line 495 "/usr/include/sys/cdefs.h"
#line 43 "/usr/include/assert.h"
#line 61 "/usr/include/assert.h"


void abort(void)  ;

int printf(const char *  , ...);

#line 2 "/Users/jleffler/src/cmd/x.c"
int main(int argc, char **argv)
{
    ((void) ((argc != 0 && argv != 0) ? 0 : ((void)printf ("%s:%u: failed assertion `%s'\n", "/Users/jleffler/src/cmd/x.c" , 4 , "argc != 0 && argv != 0"), abort()) )) ;
    return 0;
}

mccp -K x.c(节选)

我省略了大约560行,内容不是很丰富,但是主要代码是:

mccp -K x.c (excerpt)

I omitted about 560 lines of not very informative output, but the main code is:

#line 2 "/Users/jleffler/src/cmd/x.c"
int main(int argc, char **argv)
{
    /*<assert 4:5-4:35*//*!assert:0-0 4:12-4:34*/((void) ((/*<assert:0-0*/argc != 0 && argv != 0/*>*/) ? 0 : /*<__assert*//*!__assert:0-0*//*!__assert:0-1*//*!__assert:0-2*/((void)printf ("%s:%u: failed assertion `%s'\n", /*<__assert:0-1*//*<__FILE__*/"/Users/jleffler/src/cmd/x.c"/*>*//*>*/, /*<__assert:0-2*//*<__LINE__*/4/*>*//*>*/, /*<__assert:0-0*//*<assert:0-0*/"argc != 0 && argv != 0"/*>*//*>*/), abort())/*>*/))/*>*/;
    return 0;
}

或者,每行单独注释一次(手动):

Or, with comments isolated one per line (manually):

#line 2 "/Users/jleffler/src/cmd/x.c"
int main(int argc, char **argv)
{
    /*<assert 4:5-4:35*/
    /*!assert:0-0 4:12-4:34*/
    ((void) ((
      /*<assert:0-0*/
      argc != 0 && argv != 0
    /*>*/
             ) ? 0 :
    /*<__assert*/
    /*!__assert:0-0*/
    /*!__assert:0-1*/
    /*!__assert:0-2*/
    ((void)printf ("%s:%u: failed assertion `%s'\n",
    /*<__assert:0-1*/
    /*<__FILE__*/
    "/Users/jleffler/src/cmd/x.c"
    /*>*/
    /*>*/
    ,
    /*<__assert:0-2*/
    /*<__LINE__*/
    4
    /*>*/
    /*>*/
    ,
    /*<__assert:0-0*/
    /*<assert:0-0*/
    "argc != 0 && argv != 0"
    /*>*/
    /*>*/
    ), abort())
    /*>*/
    ))
    /*>*/
    ;
    return 0;
}

assert()宏实现中的错误是什么?

What is the bug in this implementation of the assert() macro?

提示:C99标准说:

§7.2.1.1 assert

assert 宏将诊断测试放入程序;它扩展为一个空表达式.执行时,如果expression(应具有标量类型)为false(即,比较等于0),则 assert 宏写入有关特定调用的信息,该调用失败(包括参数的文本,源文件的名称,源代码行)数字,以及封闭函数的名称,后者分别是预处理宏 __ FILE __ __ LINE __ 以及标识符 __ func __ ),以实现定义的格式显示在标准错误流上.它然后调用 abort 函数.

§7.2.1.1 The assert macro

The assert macro puts diagnostic tests into programs; it expands to a void expression. When it is executed, if expression (which shall have a scalar type) is false (that is, compares equal to 0), the assert macro writes information about the particular call that failed (including the text of the argument, the name of the source file, the source line number, and the name of the enclosing function — the latter are respectively the values of the preprocessing macros __FILE__ and __LINE__ and of the identifier __func__) on the standard error stream in an implementation-defined format. It then calls the abort function.

计算机正在运行MacOS X Lion(10.7.1).

The machine is running MacOS X Lion (10.7.1).

这篇关于“宏注释嵌入到注释中"的含义是什么?在mcpp中意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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