#ifdef __cplusplus [英] #ifdef __cplusplus
问题描述
我在一些代码中看到:
#ifdef __cplusplus
externC
{< br $>
#endif
这是什么意思?
谢谢
-
__mattia__
mattia说:
我已经看到了一些代码:
#ifdef __cplusplus
externC
{
#endif
这是什么意思?
这意味着某人还没有决定他们写的是哪种语言。
最好避免。
< br $>
-
Richard Heathfield< http://www.cpax.org.uk>
电子邮件:-http:// www。 + rjh @
谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>
Usenet是一个奇怪的放置" - 1999年7月29日dmr
文章< 47 *********************** @ reader4 .news.tin.it>,
mattia< ge **** @ gmail.comwrote:
>我''我们在一些代码中看到:
> #ifdef __cplusplus
extern" C"
{
#endif
是什么意思?
这与C ++有关。 AC编译器不会定义__cplusplus
,因此C编译器会将这些行编译为虚无。
此表单检测代码是否正在编译C ++
编译器,如果是,则包含externC编译器。围绕代码块的{}。
externC的含义。 {}特定于C ++,并且在C ++中意味着
所包含的代码块将使用C调用序列而不是C ++调用序列来编译其函数。 C调用序列与C ++
调用序列之间最重要的区别是C ++调用序列(通常)具有名为b $ ba隐藏参数的名称。 ;这"指的是操作的对象是
;在C ++中使用这种语法告诉C ++不要将隐藏参数放入
中,从而使定义的函数适合于从C调用
(或者,交替地,-declaring- functions因为
外部函数需要C风格的参数来调用。)
-
"当我们都认为相似时,没有人是非常想。
- Walter Lippmann
4月9日,9:26 * am,mattia< ger ... @ gmail.comwrote:
我在某些代码中看到:
#ifdef __cplusplus
* externC
* {
#endif
这是什么意思?
这意味着令牌externC如果定义了__cplusplus预处理器符号,则是
翻译单元的一部分。
某处更远,应该有匹配的
#ifdef __cplusplus
}
#endif
关闭大括号。
I''ve see in some code:
#ifdef __cplusplus
extern "C"
{
#endif
what does it mean?
Thanks
--
__mattia__
mattia said:
I''ve see in some code:
#ifdef __cplusplus
extern "C"
{
#endif
what does it mean?It means that someone hasn''t decided which language they''re writing in.
Best avoided.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
In article <47***********************@reader4.news.tin.it>,
mattia <ge****@gmail.comwrote:>I''ve see in some code:
>#ifdef __cplusplus
extern "C"
{
#endif
what does it mean?This has to do with C++. A C compiler will not defne __cplusplus
and so a C compiler will compile those lines to nothingness.
This form detects that whether the code is being compiled with a C++
compiler, and if it is, wraps extern "C" { } around the block of code.
The meaning of extern "C" { } is specific to C++, and in C++ means
that the enclosed block of code is to have its functions compiled
with C calling sequences rather than C++ calling sequences. The
single most important difference between C calling sequences and C++
calling sequences is that C++ calling sequences (usually) have
a hidden parameter named "this" that refers to the object being
operated upon; using this syntax in C++ tells C++ to not put in
that hidden parameter, thus leaving the functions defined suitable for
calling from C (or, alternately, -declaring- functions as being
external functions that need C-style parameters to call.)
--
"When we all think alike no one is thinking very much."
-- Walter Lippmann
On Apr 9, 9:26*am, mattia <ger...@gmail.comwrote:I''ve see in some code:
#ifdef __cplusplus
*extern "C"
*{
#endif
what does it mean?It means that the tokens extern "C" { are part of the
translation unit if the __cplusplus preprocessor symbol is defined.
Somewhere farther down, there should be a matching
#ifdef __cplusplus
}
#endif
to close the brace.
这篇关于#ifdef __cplusplus的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!