extern

函数的调用规则(__cdecl,__stdcall,__fastcall,__pascal)

▼魔方 西西 提交于 2019-12-12 13:47:22
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 关于函数的调用规则(调用约定),大多数时候是不需要了解的,但是如果需要跨语言的编程,比如VC写的dll要delphi调用,则需要了解。 microsoft的vc默认的是__cdecl方式,而windows API则是__stdcall ,如果用vc开发 dll给其他语言用,则应该指定__stdcall方式 。堆栈由谁清除这个很重要,如果是要写汇编函数给C调用,一定要小心堆栈的清除工作, 如果是__cdecl方式的函数,则 函数本身 (如果不用汇编写)则 不需要关心 保存参数的 堆栈 的清除 ,但是如果是 __stdcall的规则,一定要在 函数 退出(ret)前恢复堆栈 。 1.__cdecl 所谓的C调用规则。按从右至左的顺序压参数入栈,由调用者把参数弹出栈。切记:对于传送参数的内存栈是 由调用者 来维护的。 返回值在EAX中 因此,对于象printf这样变参数的函数必须用这种规则。编译器在编译的时候对这种调用规则的函数生成修饰名的饿时候,仅在输出函数名前加上一个下划线前缀,格式为 _ functionname。 2.__stdcall 按从 右至左的顺序压参数入栈,由被调用者把参数弹出栈 。_stdcall是Pascal程序的缺省调用方式,通常用于Win32 Api中,切记: 函数 自己在退出时清空堆栈

using extern to link array with pointer

情到浓时终转凉″ 提交于 2019-12-12 09:56:19
问题 Suppose I have two files: file1.c- contains global definition of an int array of size 10 named "array[10]". file2.c- contains an int pointer named "extern int *array", here I am trying to link this pointer to array. But when I check the address of array in file1.c and pointer value in file2.c, they are both different. Why it is happening? 回答1: That doesn't work, in file2.c , you need extern int array[]; since arrays and pointers are not the same thing. Both declarations must have the

How to create an extern alias for System.Core?

柔情痞子 提交于 2019-12-12 09:45:33
问题 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! 回答1: 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

No linkage at block scope?

爷,独闯天下 提交于 2019-12-12 08:26:44
问题 Do all variables declared in a block have 'no linkage'? For example: 1: If I declare a static variable: void foo() { static int i; } Would it have an internal linkage or no linkage? If no linkage, then why make it static? 2: What happens if I use extern? /*global scope*/ static int i; void foo() { extern int i; } In this case, what will be the linkage of i ? 回答1: Indeed, 'no linkage' at function scope. The goal is lifetime management: the static has the lifetime of a global static, while it

Extern C/C++ confusion in ndk - Syntax error Eclipse

旧巷老猫 提交于 2019-12-12 03:38:44
问题 I wish to run a C Code in android for which I am using android ndk. I also need to add some libraries. While building these libraries, I am getting errors because of the extern statements in the header files. Eclipse IDE shows syntax errors. I also unchecked everything at Project-->Properties--> C/C++ Code Analysis. Similar example is shown here. How to resolve this? #ifdef __cplusplus extern "C" { #endif 来源: https://stackoverflow.com/questions/33078953/extern-c-c-confusion-in-ndk-syntax

Understanding `extern` storage class specifier in C

守給你的承諾、 提交于 2019-12-12 03:37:48
问题 Consider given C codes : #include<stdio.h> extern int i; int main(){ printf("%d", i); return 0; } It gives Compilation error . While if I initialize extern int i=10; then output is 10 . #include<stdio.h> extern int i=10; //initialization statement int main(){ printf("%d", i); return 0; } And also, if I assign int i=10; then output is 10 . #include<stdio.h> extern int i; int i=10; //assignment int main(){ printf("%d", i); return 0; } And #include<stdio.h> extern int i; int main(){ int i=10; /

Google Closure Compiler - How to create an Extern for a variable (variable name can't change as it is in an Eval)

好久不见. 提交于 2019-12-12 03:17:23
问题 I am using Google Closure Compiler in "SIMPLE_OPTIMIZATIONS" mode. The JavaScript uses an "Eval" statement with the variable "_u" embedded in the string. When Google Closure Compiler obfuscates the code, the variable name is changed to "a" and I get an error that "_u" is not defined in the console. My understanding is that an Extern will solve this problem, but I'm not sure how to write it. Thoughts? Code Snippet: var FuncName = (function(){ var ht=escape(_w.location.href) function _fC(_u){

Defining extern variable in main() vs. globally

笑着哭i 提交于 2019-12-12 01:38:14
问题 Given the following header file, if 'a' is defined inside the main body, I get a warning "unused variable 'a'" and linker error "undefined reference to 'a'. header.h: #ifndef HEADER_H #define HEADER_H #include <iostream> extern int* a; void f() { std::cout<<*a <<std::endl; return; } #endif main.cpp: #include "header.h" int main() { int* a = new int(10); f(); } However, if 'a' is defined outside of main(), the program links with no errors and f() works as expected (prints 10). Why is this?

What does external linkage mean [duplicate]

吃可爱长大的小学妹 提交于 2019-12-12 01:25:49
问题 This question already has answers here : What is an undefined reference/unresolved external symbol error and how do I fix it? (32 answers) Closed 5 years ago . Consider the following code: #include <stdio.h> namespace EnclosingNmspc { namespace Nmspc { extern int a;//This a and the a defined above denote the same entity int a=5; } } extern int a; int main() { printf("%d\n",a); } There is the quote from 3.5/2: When a name has external linkage , the entity it denotes can be referred to by names

How can I define two global `const` variables to the same value in a C module?

落花浮王杯 提交于 2019-12-11 13:24:04
问题 I’m using a pair of global variables in one of my .c files, matched to a single extern declaration each in two different .h files (well, one .h file, preprocessed two ways). One is for public consumption, and one is for private use. Both are const variables. I only want to initialize one of the variables in my .c file, and then assign the second variable to the same content. Here’s the relevant contents of the .c file at the moment: struct List_methods const List = { .create = List__create,