confused about the extern keyword

This question already has an answer here: What is the effect of extern “C” in C++? 12 answers When to use extern in C++ 5 answers Obligatory point #1: this relates to global variables, so the first thing you really need/want to do is not learn how to use them, but how to avoid them. They're much more likely to lead to problems than a solution. That said, at least in the usual case,

对extern关键字感到困惑

这个问题在这里已经有了答案: C ++中extern“C”的效果是什么? 12个答案 何时在C ++ 5答案中使用extern 强制性要点#1:这涉及到全局变量,所以你真正需要/想要做的第一件事就是不学会如何使用它们,而是如何避免它们。 它们比解决方案更可能导致问题。 这就是说,至少在通常情况下,你在头文件中放置了一个extern声明。 您将变量的定义放在一个源文件中,并将头文件包含在需要访问该变量的任何其他文件中。 例如:

Extern "C" function internally uses C++ class

This question already has an answer here: What is the effect of extern “C” in C++? 12 answers This is perfectly legitimate. The purpose of extern "C" is to prevent Func() from getting its name mangled (decorated with type information) so that a C module can link to it using its plain name. C++ mangles names so that functions with the same name but different parameter lists can be

外部“C”函数内部使用C ++类

这个问题在这里已经有了答案: C ++中extern“C”的效果是什么? 12个答案 这是完全合法的。 extern“C”的目的是为了防止Func()获得其名称(用类型信息装饰),以便C模块可以使用它的普通名称链接到它。 C ++调整名称,以便可以解析具有相同名称但不同参数列表的函数(函数重载)。

How does extern "C" work in C++?

This question already has an answer here: What is the effect of extern “C” in C++? 12 answers It's probably not like that, but more like: #ifdef __cplusplus extern "C" { #endif //some includes or declarations #ifdef __cplusplus } #endif It tells the compiler to use C name mangling for whatever is declared inside the directives. The way you have it now: #ifdef __cplusplus extern

extern“C”如何在C ++中工作?

这个问题在这里已经有了答案: C ++中extern“C”的效果是什么? 12个答案 这可能不是这样,但更像是: #ifdef __cplusplus extern "C" { #endif //some includes or declarations #ifdef __cplusplus } #endif 它告诉编译器使用C名称来改变指令内部声明的内容。 你现在的方式是: #ifdef __cplusplus extern "C" {} #endif 只是死代码。 它用于通知编译器禁用大括号内定义的函数的C ++名称修改。 http://en.w

difference between extern "C" and simply extern

This question already has an answer here: What is the effect of extern “C” in C++? 12 answers extern "C" simply means that the following block of code can be compiled either using C or Cpp compiler. This is done when you have a mixture of C/C++ code and you need to keep track of language-specific features. In a bit more geeky way, the C linkage becomes compatible in presence of a

extern“C”和extern之间的区别

这个问题在这里已经有了答案: C ++中extern“C”的效果是什么? 12个答案 extern“C”只是表示可以使用C或Cpp编译器来编译以下代码块。 这是在您混合使用C / C ++代码并且需要跟踪语言特定功能时完成的。 以一种更加怪异的方式,C链接变得与Cpp编译器兼容。 代码可以是从变量/ typedef到全功能/模块声明的任何内容。 但是,如果你这样做: extern char c; // same goes true for extern int foo() 这意味着你说“我正在

What exactly do I lose when using extern "C" in C++?

This question already has an answer here: What is the effect of extern “C” in C++? 12 answers The only thing that gets dropped is name mangling of externally visible names. Function overloading by parameter types, as well as by parameter count, stop working as the result. Essentially, name resolution during the linking phase goes back to the plain old C mode (ie one name - one entry). As

在C ++中使用extern“C”时会丢失什么?

这个问题在这里已经有了答案: C ++中extern“C”的效果是什么? 12个答案 唯一被丢弃的是外部可见名称的名称改变。 作为结果,通过参数类型以及参数计数的函数重载停止工作。 实质上,链接阶段的名称解析可以回到普通的旧C模式(即一个名称 - 一个条目)。 就实现的内部结构而言,您可以继续使用标准库以及C ++ 11的所有其他优良功能。 只有外部可见实体的名称extern C被extern C更改。

When to use extern "C" in simple words?

This question already has an answer here: What is the effect of extern “C” in C++? 12 answers You need to use extern "C" in C++ when declaring a function that was implemented/compiled in C. The use of extern "C" tells the compiler/linker to use the C naming and calling conventions, instead of the C++ name mangling and C++ calling conventions that would be used otherwise.

何时以简单的词语使用extern“C”?

这个问题在这里已经有了答案: C ++中extern“C”的效果是什么? 12个答案 当声明一个在C中实现/编译的函数时,需要在C ++中使用extern "C" 。使用extern "C"告诉编译器/链接器使用C命名和调用约定,而不是C ++名称修饰, C ++调用约定,否则将被使用。 对于其他库提供的函数,几乎不需要使用extern "C" ,因为编写良好的库已经具有用于输出到C和C ++的公共API的内容。 但是,如果你编写一个

safe in C++11?

I hear that const means thread-safe in C++11. Is that true? Does that mean const is now the equivalent of Java's synchronized ? Are they running out of keywords? I hear that const means thread-safe in C++11. Is that true? It is somewhat true... This is what the Standard Language has to say on thread-safety: [1.10/4] Two expression evaluations conflict if one of them modifies a m

在C ++ 11中安全吗?

我听说const C ++ 11中的线程安全。 真的吗? 这是否意味着const现在相当于Java的synchronized ? 他们用完了关键字吗? 我听说const C ++ 11中的线程安全。 真的吗? 这是有点真... 这就是标准语言在线程安全方面所要说的: [1.10 / 4]如果其中一个修改一个内存位置(1.7),另一个访问或修改相同的内存位置,则两个表达式评估冲突。 [1.10 / 21]一个程序的执行包含一个数据竞争,如果它包含两个不同线程中的冲

what C++ idioms are deprecated in C++11

With the new standard, there are new ways of doing things, and many are nicer than the old ways, but the old way is still fine. It's also clear that the new standard doesn't officially deprecate very much, for backward compatibility reasons. So the question that remains is: What old ways of coding are definitely inferior to C++11 styles, and what can we now do instead? In answering

在C ++ 11中弃用了哪些C ++习惯用法

有了新标准,就有了新的办法,许多办法比老办法好,但老办法还是不错的。 出于向后兼容性的原因,这个新标准也没有被正式弃用。 所以现在的问题是: 旧的编码方式肯定比C ++ 11风格差,我们现在可以做什么呢? 在回答这个问题时,你可以跳过诸如“使用自动变量”这样的明显的东西。 最终类:C ++ 11提供了final说明符来防止类派生 C ++ 11 lambdas大大减少了对命名函数对象(函子)类的需求。 移动构造函数:由于对右

What does "dereferencing" a pointer mean?

请说明一个例子。 Reviewing the basic terminology It's usually good enough - unless you're programming assembly - to envisage a pointer containing a numeric memory address, with 1 referring to the second byte in the process's memory, 2 the third, 3 the fourth and so on.... What happened to 0 and the first byte? Well, we'll get to that later - see null pointers below. For a m

“取消引用”指针是什么意思?

请说明一个例子。 回顾基本术语 它通常足够好 - 除非你正在编程程序集 - 设想一个包含数字内存地址的指针 ,其中1指向进程内存中的第二个字节,2第三个,第三个,第四个等...... 0和第一个字节发生了什么? 那么,我们将在稍后介绍 - 请参阅下面的空指针。 要更准确地定义指针存储的内容以及内存和地址的关系,请参阅“关于内存地址的更多信息,以及您可能不需要知道的原因”。 当你想要访问指针指向的内存中的数据/值时

What is the meaning of prepended double colon "::"?

I found this line of a code in a class which I have to modify: ::Configuration * tmpCo = m_configurationDB;//pointer to current db and I don't know what exactly means the double colon prepended to the class name. Without that I would read: declaration of tmpCo as a pointer to an object of the class Configuration ... but the prepended double colon confuses me. I also found: typedef ::con

prepend双冒号“::”是什么意思?

我在一个需要修改的类中找到了这行代码: ::Configuration * tmpCo = m_configurationDB;//pointer to current db 而且我不知道到底是什么意味着类名前加了双冒号。 如果没有这个,我会读: tmpCo声明,作为类Configuration一个对象的指针...但是前面的双冒号混淆了我。 我还发现: typedef ::config::set ConfigSet; 这可以确保解析发生在全局名称空间中,而不是从您当前所在的名称空间开始。例如,如果您有两个不同的名