gpt4 book ai didi

macros - "macro annotations embedding in comments"在mcpp中是什么意思?

转载 作者:行者123 更新时间:2023-12-01 15:24:27 31 4
gpt4 key购买 nike

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.**

那么,“评论中的宏注释”是什么意思?

http://mcpp.sourceforge.net/

最佳答案

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

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.

因此,它会在后面留下标识扩展的宏的注释,以便您可以分辨出哪个源来自哪个宏。

插图

来源(x.c)

#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 行信息量不大的输出,但主要代码是:

#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;
}

或者,每行一个评论(手动):

#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() 宏的这个实现中的错误是什么?

提示:C99 标准说:

§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)。

关于macros - "macro annotations embedding in comments"在mcpp中是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7303532/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com