extern

C存储类

感情迁移 提交于 2019-12-06 02:19:00
C 存储类 存储类定义 C 程序中变量/函数的范围(可见性)和生命周期。这些说明符放置在它们所修饰的类型之前。下面列出 C 程序中可用的存储类: auto register static extern auto 存储类 auto 存储类是所有局部变量默认的存储类。 { int mount; auto int month; } 上面的实例定义了两个带有相同存储类的变量,auto 只能用在函数内,即 auto 只能修饰局部变量。 register 存储类 register 存储类用于定义存储在寄存器中而不是 RAM 中的局部变量。这意味着变量的最大尺寸等于寄存器的大小(通常是一个词),且不能对它应用一元的 '&' 运算符(因为它没有内存位置)。 { register int miles; } 寄存器只用于需要快速访问的变量,比如计数器。还应注意的是,定义 'register' 并不意味着变量将被存储在寄存器中,它意味着变量可能存储在寄存器中,这取决于硬件和实现的限制。 static 存储类 static 存储类指示编译器在程序的生命周期内保持局部变量的存在,而不需要在每次它进入和离开作用域时进行创建和销毁。因此,使用 static 修饰局部变量可以在函数调用之间保持局部变量的值。 static 修饰符也可以应用于全局变量。当 static 修饰全局变量时

WPF 使用SetParent嵌套窗口

扶醉桌前 提交于 2019-12-06 02:07:35
有点类似与Winform的MDI窗口。 使用函数为SetParent和MoveWindow(经常配合)。 [DllImport("user32.dll", SetLastError = true)] public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint); [DllImport("user32.dll", EntryPoint = "SetParent")] public static extern int SetParent(IntPtr hWndChild, IntPtr hWndNewParent); 给个小例子,例如嵌套TIM的聊天窗口 其中window1 就是新建的窗口 里面什么都没有写,默认 public partial class MainWindow : Window { [DllImport("user32.dll", SetLastError = true)] public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint); [DllImport("user32.dll"

Difference extern“C” vs extern

柔情痞子 提交于 2019-12-06 01:20:19
问题 Is there a difference whether I use the extern "C" specifier for the entire header, or specify extern for every function? As far as I know, there is none, since only functions and variables can be linked externally, so when I use the extern specifier before every function prototype and extern variable, I have no need to use the global extern "C" declaration!? Example A: #ifdef __cplusplus extern "C" { #endif void whatever(void); #endif Example B: extern void whatever(void); 回答1: extern "C"

Linux电源管理(7)_Wakeup events framework

£可爱£侵袭症+ 提交于 2019-12-05 20:35:57
1. 前言 本文继续“Linux电源管理(6)_Generic PM之Suspend功能”中有关suspend同步以及PM wakeup的话题。这个话题,是近几年Linux kernel最具争议的话题之一,在国外Linux开发论坛,经常可以看到围绕该话题的辩论。辩论的时间跨度和空间跨度可以持续很长,且无法达成一致。 wakeup events framework是这个话题的一个临时性的解决方案,包括wake lock、wakeup count、autosleep等机制。它们就是本文的话题。 2. wakeup events framework要解决的问题 我们知道,系统处于suspend状态,可通过wakeup events唤醒。具体的wakeup events可以是按键按下,可以是充电器插入,等等。但是,如果在suspend的过程中,产生了wakeup events,怎么办?答案很肯定,"wakeup"系统。由于此时系统没有真正suspend,所以这的"wakeup"是个假动作,实际上只是终止suspend。 但由于系统在suspend的过程中,会进行process freeze、 device suspend等操作,而这些操作可能导致内核或用户空间程序不能及时获取wakeup events,从而使系统不能正确wakeup,这就是wakeup events

Is it possible to typedef a pointer-to-extern-“C”-function type within a template?

旧城冷巷雨未停 提交于 2019-12-05 19:55:58
问题 I want to add a public typedef to a template for a pointer to a function-taking-one-argument that uses "C" language linkage. I tried: extern "C" { template <typename return_t_, typename arg1_t_> struct test { typedef return_t_ (*C_fun1_t)(arg1_t_); }; } And: template <typename return_t_, typename arg1_t_> struct test { extern "C" { typedef return_t_ (*C_fun1_t)(arg1_t_); } }; And: template <typename return_t_, typename arg1_t_> struct test { extern "C" typedef return_t_ (*C_fun1_t)(arg1_t_);

inline,宏定义,static,extern

梦想与她 提交于 2019-12-05 16:50:17
inline一般用于定义代码简洁,耗时短,不像宏定义是在预编译阶段替换,inline是在汇编阶段替换,效果一样。 一般编译器进行优化的时候会对简短方法进行这种优化,不进行声明也会进行inline,如果显示的声明为inline,会增大最后代码的大小。最终是否优化由编译器决定,这样声明了可以在头文件中定义,不用担心重复定义。 static是告诉链接器,当前文件定义的方法和变量只有当前模块可用,不能被其他的模块使用。 注意,对于 include 方式进行包含的没有影响。 include 实际是对整个文件进行包含。这个一般是对于库与库,或者 .o 与 .o 之间,可见范围由编译器进行分隔。 extern是告诉编译器,如果当前项目没有定义相关的变量, 不需要报错,在链接阶段一定会有相关的定义的。 和static 有些类似,也是使用于模块与模块之间的。 宏定义是在预编译阶段就进行替换。 可以通过 g++ -E source.cpp 的方式查看替换后的代码。 /* [root@localhost definecompile]# g++ -E test.cpp # 1 "test.cpp" # 1 "<built-in>" # 1 "<命令行>" # 1 "/usr/include/stdc-predef.h" 1 3 4 # 1 "<命令行>" 2 # 1 "test.cpp" */ int

How does extern work?

走远了吗. 提交于 2019-12-05 15:01:15
extern is a storage class in C. How exactly does it work? The output of the code given below is 20. How is this the output? #include <stdio.h> int main() { extern int a; printf("%d", a); return 0; } int a=20; Mike Seymour It means three things: The variable has external linkage , and is accessible from anywhere in the program; It has static storage duration , so its lifetime is that of the program (more or less); and The declaration is just a declaration, not a definition. The variable must also be defined somewhere (either without the extern , or with an initialiser, or in your case, both).

Bran的内核开发教程(bkerndev)-08 中断服务程序(ISR)

牧云@^-^@ 提交于 2019-12-05 14:33:20
中断服务程序(ISR)   中断服务程序(ISR)用于保存当前处理器的状态, 并在调用内核的C级中断处理程序之前正确设置内核模式所需的段寄存器。而工作只需要15到20行汇编代码来处理, 包括调用C中的处理程序。我们还需要将IDT条目指向正确的ISR以正确处理异常。   异常是导致处理器无法正常执行的特殊情况, 比如除以0结果是未知数或者非实数, 因此处理器会抛出异常, 这样内核就可以阻止进程或任务引起任何问题。如果处理器发现程序正尝试访问不允许其访问的内存, 则会引起一般保护错误。当你设置内存页时, 处理器将会产生页面错误, 但这是可以恢复的: 你可以将内存页映射到错误的地址(但这需要另开一篇教程来讲解)。   IDT的前32个条目与处理器可能产生的异常对应, 因此需要对其进行处理。某些异常会将另一个值压入堆栈中: 错误代码, 该值为每个异常的特定代码。 Exception # Description Error Code? 0 Division By Zero Exception No 1 Debug Exception No 2 Non Maskable Interrupt Exception No 3 Breakpoint Exception No 4 Into Detected Overflow Exception No 5 Out of Bounds Exception

C and C++ linkage with extern “C”

爷,独闯天下 提交于 2019-12-05 14:21:21
I have a C++ function defined in a .h file as follows and implemented in a .cpp file: extern "C" void func(bool first, float min, float* state[6], float* err[6][6]) { //uses vectors and classes and other C++ constructs } How can I call func in a C file? How do I set up my file architecture / makefile to compile this? Thanks! To call it in C, all you need to do is call it normally. Because you told the compiler to use the C calling conventions and ABI with extern "C" , you can call it normally: func(args); To compiler, use this for the C++: g++ -c -o myfunc.o myfunc.cpp Then this for the C: gcc

How to create an extern alias for System.Core?

╄→尐↘猪︶ㄣ 提交于 2019-12-05 13:31:43
I absolutely need an extern alias for System.Core in my project. Unfortunately, in a .Net 4.0 project, you cannot even add a reference to System.Core because, apparently, the build system includes it by default. Does anyone have any idea on how I can coerce the system to let me specify an extern alias for this lib? Thanks! This question is old but I ran into the same problem. As far as I understood, this is due to Visual Studio implicitly adding a reference to System.Core. You can override this by editing your csproj msbuild file and adding: <PropertyGroup>