extern

C implicit extern for global variable, when does it happen, how does it work

风格不统一 提交于 2019-12-24 05:01:49
问题 I'm trying to understand the ways in which a C global variable can be shared between multiple files (compilation units). I've read the excellent question and answer here. However after doing a few tests I'm still left with some stuff I don't get: Basically my question would be: if there's a variable declared (but not defined) in a header WITHOUT the extern keyword, is it ok to simply include that header in various compilation units in order to make available that variable to all those

C implicit extern for global variable, when does it happen, how does it work

六眼飞鱼酱① 提交于 2019-12-24 05:01:05
问题 I'm trying to understand the ways in which a C global variable can be shared between multiple files (compilation units). I've read the excellent question and answer here. However after doing a few tests I'm still left with some stuff I don't get: Basically my question would be: if there's a variable declared (but not defined) in a header WITHOUT the extern keyword, is it ok to simply include that header in various compilation units in order to make available that variable to all those

C++ 存储类

旧城冷巷雨未停 提交于 2019-12-24 04:42:27
存储类定义 C++ 程序中变量/函数的范围(可见性)和生命周期。这些说明符放置在它们所修饰的类型之前。下面列出 C++ 程序中可用的存储类: auto register static extern mutable thread_local (C++11) 从 C++ 11 开始,auto 关键字不再是 C++ 存储类说明符,且 register 关键字被弃用。 auto 存储类 自 C++ 11 以来, auto 关键字用于两种情况:声明变量时根据初始化表达式自动推断该变量的类型、声明函数时函数返回值的占位符。 C++98标准中auto关键字用于自动变量的声明,但由于使用极少且多余,在C++11中已删除这一用法。 根据初始化表达式自动推断被声明的变量的类型,如: auto f=3.14; //double auto s("hello"); //const char* auto z = new auto(9); // int* auto x1 = 5, x2 = 5.0, x3='r';//错误,必须是初始化为同一类型 register 存储类 register 存储类用于定义存储在寄存器中而不是 RAM 中的局部变量。这意味着变量的最大尺寸等于寄存器的大小(通常是一个词),且不能对它应用一元的 '&' 运算符(因为它没有内存位置)。 { register int miles; }

C function calling C++ member function - where the C code is compiled with a C compiler

本小妞迷上赌 提交于 2019-12-24 01:53:39
问题 PLEASE before closing as dupe, read the question & see why it is different (hint: it's the C compiler) I have Googled and found many, many, explanations of how a C function can call a C++ member function. They all look similar to the accepted answer to this question, from a very high rep member. It says In a header file, put extern "C" void* MyClass_create() { return new MyClass; } extern "C" void MyClass_release(void* myclass) { delete static_cast<MyClass*>(myclass); } extern "C" void

Using extern @class in order to add a category?

时光怂恿深爱的人放手 提交于 2019-12-24 01:15:08
问题 Is there a way to "promise that a class exists elsewhere" (i.e. similar to the extern keyword) and therefore avoid having to use #import statements? Here is an example of what I am trying to do: extern @class MyClass; @interface Foo : NSObject @property (nonatomic) MyClass *abc; @end Where MyClass definitely exists and is used throughout my program, but at the time I create this file, I don't know the name of the file where MyClass is defined. Update : It seems like the error is related to

add “extern C” as a compiler option for a symbol?

╄→尐↘猪︶ㄣ 提交于 2019-12-23 21:08:19
问题 I'm working with FIPS Capable OpenSSL. The source code is sequestered and cannot be changed. To link to the static version of the OpenSSL library, all we need to do is: export FIPS_SIG=`find /usr/local/ssl -iname incore` export CC=`find /usr/local/ssl -iname fipsld` export FIPSLS_CC=`find /usr/bin -iname gcc` Then, simply perform: $CC $CFLAGS <sources> -o myprogram <openssl libs> The reasons for the gyration is OpenSSL will insert an additional source file - fips_premain.c - and compile it

extern function with macro

走远了吗. 提交于 2019-12-23 17:16:24
问题 Im having a linker problem in Objective C when i attempt to do a marco with a extern function. Any idea why? Header file To assist in doing comparison with the device version extern NSString* getOperatingSystemVerisonCode(); #if TARGET_OS_IPHONE // iOS #define DEVICE_SYSTEM_VERSION [[UIDevice currentDevice] systemVersion] #else // Mac #define DEVICE_SYSTEM_VERSION getOperatingSystemVerisonCode() #endif #define COMPARE_DEVICE_SYSTEM_VERSION(v) [DEVICE_SYSTEM_VERSION compare:v options

Two static variables in same name(two different file) and extern one of them in any other file

跟風遠走 提交于 2019-12-23 17:08:54
问题 Declaring a variable as static in one file and do a extern declaration in another file - i thought this will give an error while linking as the extern variable will not be seen in any object, as the one which declared in other file was with qualifier static. But somehow the linker(renesas) didn't show any error and created executable. If the above usecase was correct, what will happen if 2 variables be declared as static in 2 different files and another in another file with extern declaration

C++ global extern constant defined at runtime available across multiple source files

醉酒当歌 提交于 2019-12-23 13:04:05
问题 I have an integer constant that is to be defined at runtime. This constant needs to be available globally and across multiple source files. I currently have the following simplified situation: ClassA.h declares extern const int someConstant; ClassA.cpp uses someConstant at some point. Constants.h declares extern const int someConstant; main.cpp includes ClassA.h and Constants.h , declares const int someConstant , and at some point during main() tries to initialize someConstant to the real

C++: namespace conflict between extern “C” and class member

三世轮回 提交于 2019-12-23 10:26:18
问题 I stumbled upon a rather exotic c++ namespace problem: condensed example: extern "C" { void solve(lprec * lp); } class A { public: lprec * lp; void solve(int foo); } void A::solve(int foo) { solve(lp); } I want to call the c function solve in my C++ member function A::solve. The compiler is not happy with my intent: error C2664: 'lp_solve_ilp::solve' : cannot convert parameter 1 from 'lprec *' to 'int' Is there something I can prefix the solve function with? C::solve does not work 回答1: To