extern

What is the correct way of using extern for global variables?

旧街凉风 提交于 2019-12-31 03:21:12
问题 file a.cc int a = 0; file b.cc #include "a.cc" file main.cc #include "b.cc" extern int a; int main() { } g++ -c a.cc g++ -c b.cc g++ main.cc a.o b.o error: multiple definitions of a What am I doing wrong here? 回答1: You include a .cc (or .cpp ) files, which is wrong. Do not do that. You need a header, and in that put the extern int a; : // a.h // include guards omitted extern int a; // a.cc #include "a.h" int a; // b.cc #include "a.h" // main.cc #include "a.h" int main(){ // use a } 回答2: You

round ceil floor

♀尐吖头ヾ 提交于 2019-12-31 01:07:52
转载:http://blog.csdn.net/u014624597/article/details/23868729 extern float ceilf(float); extern double ceil(double); extern long double ceill(long double); extern float floorf(float); extern double floor(double); extern long double floorl(longdouble); extern float roundf(float); extern double round(double); extern long double roundl(longdouble); round:如果参数是小数,则求本身的四舍五入。 ceil:如果参数是小数,则求最小的整数但不小于本身. floor:如果参数是小数,则求最大的整数但不大于本身. Example:如何值是3.4的话,则 3.4 -- round 3.000000 -- ceil 4.000000 -- floor 3.00000 CGRectMake(floorf(self.view.bounds.size.width*0.5f - 39.f*0.5f),self.view.bounds.size.height -57

extern variable causes multiple definition error

▼魔方 西西 提交于 2019-12-30 21:37:13
问题 I have been trying to use extern in order to use variable that is previously defined. I have not used extern before and now I need to use it in order to define variable just once and use them across multiple files I have written minimized version of code for this question. I have four files lib.h #ifndef LIB_H #define LIB_H #include <iostream> namespace lib { extern bool initialized; bool initialized = false; static void isInit(char* parent) { std::cout << "Library for [" << parent << "]

设备驱动模型-device、driver、bus(2/2)

吃可爱长大的小学妹 提交于 2019-12-30 01:22:42
目录 一. device设备描述 1.1 内核结构 1.1.1 设备 struct device 1.1.2 设备属性 struct device_attribute 1.2 相关操作接口 1.2.1 设备操作接口 1.2.2 设备属性操作接口 二. driver设备驱动描述 2.1 内核结构 2.1.1 struct device_driver驱动数据结构 2.1.2 struct driver_attribute 设备属性 2.2 相关操作接口 2.2.1 驱动操作接口 2.2.2 驱动属性操作接口 三. 设备、驱动配对之bus总线---实例 3.1 device实例 3.2 driver实例 3.3 bus实例 一. device设备描述 1.1 内核结构 1.1.1 设备 struct device struct device { struct device *parent; /*设备私有数据*/ struct device_private *p; struct kobject kobj; /*设备名*/ const char *init_name; /* initial name of the device */ /*设备类型*/ const struct device_type *type; struct mutex mutex; /* mutex to

C#调用Win32_的API函数--User32.dll

雨燕双飞 提交于 2019-12-29 08:12:40
来自森大科技官方博客 http://www.cnsendblog.com/index.php/?p=230 GPS平台、网站建设、软件开发、系统运维,找森大网络科技! http://cnsendnet.taobao.com C#调用Win32 的API函数--User32.dll Win32的API函数是微软自己的东西,可以直接在C#中直接调用,在做WinForm时还是很有帮助的。有时候我们之直接调用Win32 的API,可以很高效的实现想要的效果。 代码 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices; namespace WindowsAPI { class CSharp_Win32Api { #region User32.dll 函数 /// <summary> /// 该函数检索一指定窗口的客户区域或整个屏幕的显示设备上下文环境的句柄,以后可以在GDI函数中使用该句柄来在设备上下文环境中绘图。hWnd:设备上 下文环境被检索的窗口的句柄 /// </summary> [DllImport("user32.dll", CharSet = CharSet.Auto)] public

static const Vs extern const

倾然丶 夕夏残阳落幕 提交于 2019-12-28 08:09:44
问题 I have been using static const in my header files as so: static NSString * const myString = @"foo"; But have read that this is not the 'safe' or correct way of doing this. Apparently, if I want my const strings to be accessed from another class, I should be declaring the string in my .h as: extern NSString * const myString; Then in my .m file: NSString * const myString = @"foo"; Is this correct? If so, what is the reason not to declare it as static directly in my .h file? It works perfectly

“FOUNDATION_EXPORT” vs “extern”

南楼画角 提交于 2019-12-28 03:18:08
问题 I would like to ask what's the reason behind using FOUNDATION_EXPORT instead of extern in Objective C projects. I've checked this question and using FOUNDATION_EXPORT has earned whopping 340 points (1st place) whereas using extern only 74 points (2nd place). Could anybody explain why? Is there any practical reason for using FOUNDATION_EXPORT instead of extern ? Thanks! 回答1: If you look in NSObjCRuntime.h (in Foundation) you will see that FOUNDATION_EXPORT compiles to extern in C, extern "C"

Why can't templates be within extern “C” blocks?

不问归期 提交于 2019-12-28 03:03:31
问题 This is a follow-up question to an answer to Is it possible to typedef a pointer-to-extern-“C”-function type within a template? This code fails to compile with g++ , Visual C/C++, and Comeau C/C++ with basically the same error message: #include <cstdlib> extern "C" { static int do_stuff(int) { return 3; } template <typename return_t_, typename arg1_t_> struct test { static void foo(return_t_ (*)(arg1_t_)) { } }; } int main() { test<int, int>::foo(&do_stuff); return EXIT_SUCCESS; } g++ says

Why can't templates be within extern “C” blocks?

戏子无情 提交于 2019-12-28 03:03:04
问题 This is a follow-up question to an answer to Is it possible to typedef a pointer-to-extern-“C”-function type within a template? This code fails to compile with g++ , Visual C/C++, and Comeau C/C++ with basically the same error message: #include <cstdlib> extern "C" { static int do_stuff(int) { return 3; } template <typename return_t_, typename arg1_t_> struct test { static void foo(return_t_ (*)(arg1_t_)) { } }; } int main() { test<int, int>::foo(&do_stuff); return EXIT_SUCCESS; } g++ says

windows消息机制与实例

六眼飞鱼酱① 提交于 2019-12-27 00:09:24
windows发送窗口消息   所需工具:spy++,visual studio 2017,c#语言    技术路线:首先通过spy++获得所要操纵的窗口的句柄,函数的原型声明为:   [DllImport("user32.dll")] public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);   此函数获得目标窗口的句柄,如果要获得某个子窗口的句柄,通过以下函数可获得:   [DllImport("User32.dll ")] public static extern IntPtr FindWindowEx(IntPtr parent, IntPtr childe, string strclass, string FrmText);   对目标窗口的操作(发送指令),使用的函数原型如下:   [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);   我通过SendMessage函数发送的是绘图动作,具体包括鼠标的down,move,up   另一个发送消息的函数