extern

“extern const” vs “extern” only

一世执手 提交于 2019-12-02 20:38:13
I've seen 2 ways of creating global variables, what's the difference, and when do you use each? //.h extern NSString * const MyConstant; //.m NSString * const MyConstant = @"MyConstant"; and //.h extern NSString *MyConstant; //.m NSString *MyConstant = @"MyConstant"; the former is ideal for constants because the string it points to cannot be changed: //.h extern NSString * const MyConstant; //.m NSString * const MyConstant = @"MyConstant"; ... MyConstant = @"Bad Stuff"; // << YAY! compiler error and //.h extern NSString *MyConstant; //.m NSString *MyConstant = @"MyConstant"; ... MyConstant = @

Linux设备驱动程序 之 完成量

元气小坏坏 提交于 2019-12-02 19:13:26
内核编程中常见的一种模式是,在当前线程之外初始化某个活动,然后等待该活动的结束;这个活动可能是,创建一个新的内核线程或者新的用户空间进程、对一个已有进程的某个请求,或者某种类型的硬件动作等; 内核提供了完成量(completion)来完成上述需求;完成量是一个轻量级的机制,它允许一个线程告诉另一个线程某个工作已经完成;为了使用完成量,代码需要包含<linux/completion.h>;可以利用下面的宏静态的创建和初始化完成量; 1 #define DECLARE_COMPLETION(work) 或者使用下面的方法动态的创建和初始化完成量; 1 struct completion my_completion; 2 /* 初始化函数 */ 3 static inline void init_completion(struct completion *x) 需要等待完成,可以调用下面的方法,这些方法都以wait_for_completion开头,区别在于比如是否可以打断,是否提供超时等; 1 extern void wait_for_completion(struct completion *); 2 extern void wait_for_completion_io(struct completion *); 3 extern int wait_for_completion

How to declare my very own CGRectZero like constant?

有些话、适合烂在心里 提交于 2019-12-02 18:38:37
This is a newbie C/Objective-C question :-) Let say I want a CGRectOne and a CGRectTwo constants. How can I declare that? Thanks, Jérémy The other answers are fine - in some cases -. A) declaring it static will emit a copy per translation. That is fine if it is visible to exactly one translation (i.e. its definition is in your .m/ .c file). Otherwise, you end up with copies in every translation which includes/imports the header with the static definition. This can result in an inflated binary, as well as an increase to your build times. B) const CGRect CGRectOne = {...}; will emit a symbol in

How to prevent Closure Compiler from renaming any property or method of a specific object?

只愿长相守 提交于 2019-12-02 18:07:54
问题 I am working with a huge 3rdparty library (Babylon JS) that will be served from its own CDN and cannot be included in my Closure Compiler run. The library contains one object and everything defined as parts of it. It has no externs file available so I started to write one but it is growing quickly. It would be easier to just tell Closure Compiler to not mangle any properties I am setting, including the ones I am setting on objects created by constructors on the object. EDIT: Added the name of

类型限定符

流过昼夜 提交于 2019-12-02 11:41:34
extern:声明一个变量,extern 声明的变量没有建立存储空间 const:定义一个常量,常量的值不能修改 volatile:防止编译器优化代码 register:定义寄存器变量,提高效率。如果 CPU 有空闲寄存器,register 就生效,如果没有空闲寄存器,那么 register 无效。 来源: https://www.cnblogs.com/nnngu/p/11743447.html

How to prevent Closure Compiler from renaming any property or method of a specific object?

给你一囗甜甜゛ 提交于 2019-12-02 11:19:05
I am working with a huge 3rdparty library ( Babylon JS ) that will be served from its own CDN and cannot be included in my Closure Compiler run. The library contains one object and everything defined as parts of it. It has no externs file available so I started to write one but it is growing quickly. It would be easier to just tell Closure Compiler to not mangle any properties I am setting, including the ones I am setting on objects created by constructors on the object. EDIT: Added the name of the library. The Closure Compiler has no feature that would allow you to say "don't rename any

extern的用法

▼魔方 西西 提交于 2019-12-02 10:56:49
extern有以下三种用法: 1.用于修饰变量。 变量可以分为全局变量和局部变量两种。在一个工程的各个文件中定义的全局变量相互之间是可见的,故我们不能在两个文件中定义同名的全局变量,而可以在文件中使用在另一个文件中定义的全局变量来获取信息(不推荐使用,会降低代码的易读性)。可以在文件中的任意位置使用如下语法来使用另一个文件中的全局变量。 extern 类型名 变量名; 上面的语法相当于一个声明(注意不可以在“声明”时对变量赋值,而可以在定义该变量出赋值,如果定义时未赋值,则全局变量默认值为0),之后我们便可以在这个声明的作用域内像使用一个普通变量一样使用这个变量(可以改变其值)。即:如果你在文件开头声明这个变量便可以在这个文件中随意使用这个变量,但不能在函数外面给变量赋值(没有意义,而且会报错)。一般的用法有两种:一种是在需要使用时使用上面的语法声明变量。另一种是将上述语句放在头文件中,这样便可以在包含该头文件的文件中使用该变量。 2.用于修饰函数声明。 函数和变量不同,函数都是全局的。我们只需在使用该函数的文件中声明该函数即可。故从对编译器来说有没有extern是一样的,但在写代码时在函数声明前加extern在一定程度上会提升代码的易读性(现在IDE都很好用,故extern在函数声明中基本没用)。其语法就是: extern 函数声明语法 3.extern “C”。

Why do enumeration constants have no linkage?

六眼飞鱼酱① 提交于 2019-12-02 06:44:13
问题 I'm trying to understand linkage of enumeration constant s and could not find a clear answer in the Standard N1570 . 6.2.2(p6) : The following identifiers have no linkage: an identifier declared to be anything other than an object or a function; an identifier declared to be a function parameter; a block scope identifier for an object declared without the storage-class specifier extern . So I need to understand that constants are not objects. Object is defined as 3.15 : region of data storage

Accesing global variable giving linker error in objective C

房东的猫 提交于 2019-12-02 06:37:35
问题 I have declared a global variable like below extern NSString *name; @interface viewcontrollerOne{} in implementation file i am accessing that global variable in some method like -(void)someMethod { name = @"hello"; } but this is giving linker error. "name", referenced from: -[viewcontrollerOne someMethod] in viewcontrollerOne.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation) 回答1: The following is merely a

Why 'extern' storage class works differently in functions?

爱⌒轻易说出口 提交于 2019-12-02 05:47:13
问题 The following snippet works fine extern int i; int i; int main(){ return 0; } Here what I got is, 'i' is declared and then defined. Since there is only one definition so thats perfectly fine. int main(){ extern int i; int i; return 0; } Now, the above one gives the following error new.cpp: In function ‘int main()’: new.cpp:5:6: error: redeclaration of ‘int i’ int i; ^ new.cpp:4:13: note: previous declaration ‘int i’ extern int i; Whats the problem here? Here also there is single definition of