extern

Function templates: extern template vs explicit specialisation

喜夏-厌秋 提交于 2019-12-10 21:45:57
问题 Consider the following function template declaration: template <typename T, typename = std::enable_if_t<std::is_same_v<T, int>>> void foo(T i); There is only one possible valid instantiation of this template, namely with T = int . I'd like to put this definition in an implementation file. I can think of two possible ways of doing so. (If you're wondering why on earth I'd do this rather than just saying void foo(int i) , it's because the template version prevents implicit conversions at the

are extern variables initialized to their default value?

老子叫甜甜 提交于 2019-12-10 21:05:39
问题 I know that if a char array is a global or a static local, its elements get initialized to \0's, but what if the char array is an extern variable? 回答1: If the variable was declared as extern but is nonglobal, it too receives the same initialization handling. For instance namespace A { extern int x; int x;} This nonglobal variable will be initialized to zero. All namespace scope variables receive this handling. 回答2: An extern variable is just a declaration. The variable is initialized in the

GDI32Api、Direct3D屏幕截图

依然范特西╮ 提交于 2019-12-10 17:35:34
GDI32Api、Direct3D屏幕截图 最近因为工作需要,认真研究了一下屏幕截图的方法。 最主要的方法有两种,一、调用windows GDI32 API函数。二、使用DirectX9.0来实现。 另外,光注了一下Microsoft Expression Encoder 4 Screen Capture这个微软新出的功能,Expression Encoder 4 可实现屏幕录制,录制 文件格式为WMV ,为免费使用版本,Expression Encoder 4 Pro为 收费版本。 还 看了一下基于windows图形驱动技术的屏幕截图方法 ,文章链接地址: http://blog.csdn.net/jia162/article/details/2509974 。实现起来可能比较困难与复杂。没找到实例参考及技术实现的算法,因此也就没有深入研究。 下面两种方法 一、GDI32 API截图, 600*480大小生成Bitmap位图大概需要45ms左右 ,生成位图并save成bmp文件需要大概110ms左右,图片越大,耗费的时间越长,效率比较低。 二、DirectX截图,是把整个屏幕的拷贝到内存里,再进行截取,执行拷贝屏幕的方法g_pd3dDevice->GetFrontBufferData(0, g_pSurface) 需要80ms-100ms,效率也比较低 。

C and C++ linkage with extern “C”

▼魔方 西西 提交于 2019-12-10 06:39:55
问题 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! 回答1: 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

Block scope linkage C standard

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-10 04:37:05
问题 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 . { static int a; //no linkage } For an identifier declared with the storage-class specifier extern in a scope in which a prior declaration of that identifier is visible, if the prior declaration specifies internal or external linkage,

Why can extern be applied to definitions?

ε祈祈猫儿з 提交于 2019-12-10 02:41:55
问题 Why is this legal? extern int foo = 0xF00; // Gets a warning, still compiles extern void bar() { // No warning int x; } Is there a reason to why this is allowed? 回答1: Sometimes it's useful extern const int foo = 0xF00; Without the extern , in C++ foo would be static and have internal linkage (which means you could not use foo from another translation unit). The extern in both cases in your example is redundant. In C99 an extern can make a difference for inline functions.. 回答2: In the function

How to declare extern 2d-array in header?

落爺英雄遲暮 提交于 2019-12-10 02:39:44
问题 We have this declaration in LCD.c: unsigned char LCD[8][64] = {((unsigned char) 0)}; And in LCD.h we want to have something like: extern unsigned char LCD[][]; We get this error: Error[Pe098]: an array may not have elements of this type 回答1: You need, at a minimum, to include the right-most column size for a 2-D array. You can declare it like this: extern unsigned char LCD[][64]; Otherwise the compiler would not be able to compute the offset after the first row. 回答2: In C an array does not

C++/CLI->C# error C2526: C linkage function cannot return C++ class

百般思念 提交于 2019-12-10 02:26:40
问题 I have a simple .NET dll built with VS2010 C# that exposes 2 static members of a class public class Polygon { public static void Test(int test) {} public static void Test(List<int> test) {} } I then created a Console app from VS2010 C++ and added this function above _tmain extern "C" void TestMe() { Polygon::Test(3); } Adding the reference and compiling gives me this error 1>WierdError.cpp(9): error C2526: 'System::Collections::Generic::List<T>::GetEnumerator' : C linkage function cannot

C语言中,声明和定义的区别

自作多情 提交于 2019-12-09 18:03:42
目录 一、声明和定义的区别 什么是定义 什么是声明 区别 二、针对变量时 三、针对函数时 四、参考 一、声明和定义的区别 什么是定义 定义就是创建一个对象,给它分配内存并取名字(变量名或对象名),还可以指定初值。另外,一个变量或对象只能被定义一次,否则编译器会提示重复定义。 什么是声明 用于向程序表明变量的类型和名字。告诉编译器这个名字已使用,别的地方不能再用它作为变量名或对象名。另外,声明可以出现多次。 区别 对象分配了内存,声明没有分配内存。 定义也是声明,extern声明不是定义(通过使用extern关键字声明而不定义)。 带有初始化的声明必定是定义。 二、针对变量时 除非有extern关键字,否则都是变量的定义。 extern int i ; //声明 int i ; //定义 三、针对函数时 带有{ }的就是定义,否则就是声明 extern int max ( int a1 , int a2 ) ; //声明 四、参考 [1] https://blog.csdn.net/gatieme/article/details/50640424 [2] https://www.cnblogs.com/haore147/p/3647466.html 来源: CSDN 作者: 我还是那个内向男孩 链接: https://blog.csdn.net/u013354678/article

C中的extern-static-const关键词

老子叫甜甜 提交于 2019-12-09 17:12:34
#@date: 2014-06-14 #@author: gerui #@email: forgerui@gmail.com ###Contents extern的作用一般是用来声音一个外部变量和函数。一般在头文件hello.h中进行 extern int a; 的声明,在hello.c中进行 a = 10; 的定义。 如果在hello.h中既声明又定义,则会引起一个问题。如,hello.h中定义一个 extern int a = 2; ,hello1.c中 #include "hello.h" ,hello2.c中同样也 #include "hello.h" ,这样会出现a重定义而报错。所以,一般使用 extern声明变量时,不进行定义 。如果一定需要进行定义的话,那么hello2.c中的 #include "hello.h" 语句就要去掉,换成如下语句: extern int a; void print(){ cout<<a<<endl; } 这样编译器会自动查找外部a定义的地方。 static在hello.h中 声明一个全局static int aa = 1;时一般会同时进行定义 ,这样在hello1.c中和hello2.c中共同使用aa这个变量。 当使用 extern C 关键词时,表明采用C的格式生成变量或函数名称,因为C++由于重载的函数同名的存在,会在中间生成一个别名