帮助C代码 [英] Help on C code

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

问题描述

我对下面给出的代码片段感到困惑。


int main(int argc,char ** argv)

{

AA(主要)


USENOT(argc);

USENOT(argv);


退出(0);


返回;

}


而AA被定义为以下任何一种一些

条件


#define AA(a)ar [i ++] = #a;



#define AA(a)printf(#a" \ n");



#define AA(a);


ar定义为

extern char * ar [];


USENOT定义为

#define USENOT(x)(x = x)


1.有人可以解释在进入函数后发生的事情

main in all AA值的三种情况。


2.可能是USENOT的目的。

I am confused about the code snippet given below.

int main(int argc, char** argv)
{
AA( main )

USENOT( argc );
USENOT( argv );

exit( 0 );

return;
}

whereas AA is defined as any one of the following based on some
condition

#define AA(a) ar[i++] = #a;
or
#define AA(a) printf(#a "\n");
or
#define AA(a) ;

ar is defined as
extern char *ar[];

USENOT is defined as
#define USENOT(x) (x=x)

1.Can somebody explain what''s happening after entering the function
main in all the three cases of the values of AA.

2. what may be the USENOT''s purpose.

推荐答案

m _ ** *****@yahoo.com (PranjalMishra)写道:

新闻:9b ********************* *****@posting.google.c om:
m_*******@yahoo.com (PranjalMishra) wrote in
news:9b**************************@posting.google.c om:
我对下面给出的代码片段感到困惑。

int main(int argc,char ** argv)
{
AA(主要)

USENOT(argc);
USENOT(argv);

退出(0 );

返回;
}
而AA根据某些条件被定义为以下任何一种情况
#define AA(a)ar [i ++] = #a;

#define AA(a)printf(#a" \ n");

#define AA(a);

ar定义为
extern char * ar [];

USENOT定义为
#define USENOT (x)(x = x)

1.有人可以解释在所有三种AA值的情况下进入函数后发生的事情。


只需自己运行程序就可以编写3种不同的方式。

2.可能是USENOT的目的。
I am confused about the code snippet given below.

int main(int argc, char** argv)
{
AA( main )

USENOT( argc );
USENOT( argv );

exit( 0 );

return;
}

whereas AA is defined as any one of the following based on some
condition

#define AA(a) ar[i++] = #a;
or
#define AA(a) printf(#a "\n");
or
#define AA(a) ;

ar is defined as
extern char *ar[];

USENOT is defined as
#define USENOT(x) (x=x)

1.Can somebody explain what''s happening after entering the function
main in all the three cases of the values of AA.
Just run the program yourself compiled the 3 different ways.
2. what may be the USENOT''s purpose.



安静编译器警告argc和argv没有被使用。在这种情况下,

作者可能最好将main()定义为int main(void)。


-

- 标记 - >

-



To quiet the compiler warning about argc and argv not being used. The
author might better have defined main() as int main(void) in this case.

--
- Mark ->
--


PranjalMishra写道:
PranjalMishra wrote:
我对下面给出的代码片段感到困惑。

int main(int argc,char ** argv)
{
AA(主)

USENOT(argc);
USENOT (argv);

退出(0);

返回;
}
而AA被定义为以下任何一种基于某些条件

#define AA(a)ar [i ++] = #a;

#define AA(a)printf(#a" ; \ n");

#define AA(a);

ar定义为
extern char * ar [];

USENOT定义为
#define USENOT(x)(x = x)

1.有人可以解释进入函数后发生的事情
main在所有三个AA值的情况下。

2.可能是USENO T'的目的。
I am confused about the code snippet given below.

int main(int argc, char** argv)
{
AA( main )

USENOT( argc );
USENOT( argv );

exit( 0 );

return;
}

whereas AA is defined as any one of the following based on some
condition

#define AA(a) ar[i++] = #a;
or
#define AA(a) printf(#a "\n");
or
#define AA(a) ;

ar is defined as
extern char *ar[];

USENOT is defined as
#define USENOT(x) (x=x)

1.Can somebody explain what''s happening after entering the function
main in all the three cases of the values of AA.

2. what may be the USENOT''s purpose.




该片段基本上是为您提供功能跟踪。在第一个

实例中,它将函数的名称保存在字符串数组中。

然后,您可以随意遍历该数组。如果:


#define AA(a)ar [i ++] = #a;

AA(主要)


预编译器将扩​​展AA宏,替换a,(和#a是

参数的字符串化版本)将其发送给编译器:


ar [i ++] =" main";


如果当前没有定义变量''i',这将无法编译。


所以第二个现在应该是显而易见的:


#define AA(a)printf(#a" \ n");

AA(主要)


预编译器将发送:

printf(" main"" \ n");


而且,第三种情况只会吃参数,因为宏是空的:


#define AA(a)
AA(主要)


将发送:

(无)


我期待USENOT是一个尚未定义的宏的占位符,因为它确实没有任何用处。


David Logan



The snippet is basically giving you a function trace. In the first
instance, it is saving the name of the function in an array of strings.
You can then traverse that array at will. If:

#define AA(a) ar[i++] = #a;
AA(main)

the precompiler will expand the AA macro, replacing "a", (and #a is a
"stringized" version of the parameter) sending this to the compiler:

ar[i++] = "main";

This will not compile if the variable ''i'' is not also defined, of course.

So the second should now be obvious:

#define AA(a) printf(#a "\n");
AA(main)

the precompiler will send:
printf("main" "\n");

And, the third case will simply eat the parameter, since the macro is empty:

#define AA(a)
AA(main)

will send:
(nothing)

I expect USENOT is a placeholder for a macro that has not yet been
defined, since it really does nothing useful.

David Logan


David Logan< dj ****** @ comcast.net>写在

news:7ehAc.62224
David Logan <dj******@comcast.net> wrote in
news:7ehAc.62224


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

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