滥用C / C ++评论 [英] Abusing C/C++ comments

查看:79
本文介绍了滥用C / C ++评论的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我记得几年前我看过一段代码,它使用了两个/ * *的

组合/和//这样你就可以确定源代码的

编译类型。我不记得究竟是什么发生了什么,但是我认为它就像是源代码是由交流编译器编译的
变量的值变为1如果

它是用c​​ ++编译器编译的,那么这个值就变成了0.你知道怎么用

我能找到它吗?


任何想法?


提前致谢,

Hello all,

I remember that I saw a piece of code a few years ago, it was using a
combination of both /* */ and // such that you could determine the
compile type of the source code. I don''t remember exactly what was
happening, but I assume it was something like if the source code was
being compiled by a c compiler the value of a variable became 1 and if
it was compiled with c++ compiler the value became 0. Do you know how
can I find that ?

Any ideas ?

Thanks in advance,

推荐答案



Hapary < ha **** @ gmail.com在留言中写道

news:11 ********************* @ y80g2000hsf.googlegro ups .com ...

"Hapary" <ha****@gmail.comwrote in message
news:11*********************@y80g2000hsf.googlegro ups.com...

Hello all,


我记得几年前我看过一段代码,它使用了/ * * /和//的组合

,这样就可以确定源代码的

编译类型。我不记得究竟是什么发生了什么,但是我认为它就像是源代码是由交流编译器编译的
变量的值变为1如果

它是用c​​ ++编译器编译的,那么该值就变为0.你知道如何找到

吗?
Hello all,

I remember that I saw a piece of code a few years ago, it was using a
combination of both /* */ and // such that you could determine the
compile type of the source code. I don''t remember exactly what was
happening, but I assume it was something like if the source code was
being compiled by a c compiler the value of a variable became 1 and if
it was compiled with c++ compiler the value became 0. Do you know how
can I find that ?



/ * * /是一个合法的C ++注释,而//不是C中的合法序列.C ++

注释互相评论。我无法想到实现这一目标的方法。

标准的,可接受的方式是使用为此目的提供的#ifdef __cplusplus构造




-

免费游戏和编程好东西。
http://www.personal.leeds.ac.uk/~bgy1mm

/* */ is a legal C++ comment whilst // is not a legal sequence in C. C++
comments comment each other out. I can''t think of a way to achieve this.
The standard, acceptable way is to use the #ifdef __cplusplus construct
provided for the purpose.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm


Malcolm McLean写道:
Malcolm McLean wrote:

>

" Hapary" < ha **** @ gmail.com在留言中写道

news:11 ********************* @ y80g2000hsf.googlegro ups .com ...
>
"Hapary" <ha****@gmail.comwrote in message
news:11*********************@y80g2000hsf.googlegro ups.com...

> Hello all,

我记得几年前我看过一段代码,它是使用/ * * /和//的组合,以便确定源代码的编译类型。我不记得到底发生了什么,但我认为这就像是如果源代码是由ac编译器编译的,变量的值变为1并且如果
它是用c ++编译器编译的,值变为0.你知道我怎么能找到它吗?
>Hello all,

I remember that I saw a piece of code a few years ago, it was using a
combination of both /* */ and // such that you could determine the
compile type of the source code. I don''t remember exactly what was
happening, but I assume it was something like if the source code was
being compiled by a c compiler the value of a variable became 1 and if
it was compiled with c++ compiler the value became 0. Do you know how
can I find that ?



/ * * /是一个合法的C ++评论,而/ /不是C中的合法序列。

/* */ is a legal C++ comment whilst // is not a legal sequence in C.



它是在C99。


-

Ian Collins。

It is in C99.

--
Ian Collins.


" Malcolm McLean" < re ******* @ btinternet.comwrites:
"Malcolm McLean" <re*******@btinternet.comwrites:

" Hapary" < ha **** @ gmail.com在留言中写道

news:11 ********************* @ y80g2000hsf.googlegro ups .com ...
"Hapary" <ha****@gmail.comwrote in message
news:11*********************@y80g2000hsf.googlegro ups.com...

> Hello all,

我记得几年前我看过一段代码,它是使用/ * * /和//的组合,以便确定源代码的编译类型。我不记得到底发生了什么,但我认为这就像是如果源代码是由ac编译器编译的,变量的值变为1并且如果
它是用c ++编译器编译的,值变为0.你知道我怎么能找到它吗?
>Hello all,

I remember that I saw a piece of code a few years ago, it was using a
combination of both /* */ and // such that you could determine the
compile type of the source code. I don''t remember exactly what was
happening, but I assume it was something like if the source code was
being compiled by a c compiler the value of a variable became 1 and if
it was compiled with c++ compiler the value became 0. Do you know how
can I find that ?



/ * * /是一个合法的C ++评论,而/ /不是
C中的合法序列.C ++注释互相评论。我无法想到一个方法来实现这个目标。

标准的,可接受的方式是使用#ifdef __cplusplus

构造为此目的提供。

/* */ is a legal C++ comment whilst // is not a legal sequence in
C. C++ comments comment each other out. I can''t think of a way to
achieve this.
The standard, acceptable way is to use the #ifdef __cplusplus
construct provided for the purpose.



//在C99中引入评论。


在C90中,//可以是一个除法运算符,紧接着是

/ * * * /评论的第一个字符。


例如:


#include < stdio.h>

int main(无效)

{

char * messages [] = {

" //不接受评论,

" //评论被接受"

};

int i = 2 / / ** / 2

- 1;

puts(messages [i]);

返回0;

}


-

Keith Thompson(The_Other_Keith) ks *** @ mib.org < http://www.ghoti.net/~kst>

圣地亚哥超级计算机中心< *< http://users.sdsc.edu/ ~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。

- Antony Jay和Jonathan Lynn,是部长

// introduces a comment in C99.

In C90, // could be a division operator immediately followed by the
first character of a /* ... */ comment.

For example:

#include <stdio.h>
int main(void)
{
char *messages[] = {
"// comments are not accepted",
"// comments are accepted"
};
int i = 2 //**/ 2
- 1;
puts(messages[i]);
return 0;
}

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"


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

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