Search Results

Search found 543 results on 22 pages for 'extern'.

Page 1/22 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Use of extern in C++ dll

    - by dom_beau
    I declare then instantiate a static variable in a DLL. // DLL.h class A { //... }; static A* a; // DLL.cpp A* a = new A; So far, so good... I was suggested to use extern rather than static. extern A* a; // in DLL.h No problem with that but the extern variable must be declared somewhere. I got Invalid storage class member. In other words, what I was used to do is to declare a variable in a source file like this: // In src.cpp A a; then extern declare it in another source file in the same project: // In src2.cpp extern A a; so it is the same object a at link time. Maybe it is not the right thing to do? So, where to declare the variable that is now extern? Note that I used static declaration in order to see the variable instantiated as soon as the dll is loaded. Note that the current use of static works most of the time but I think I observe a delay or something like this in the variable instantiation while it should always be instantiated at load time. I'm investigating this problem for a week now and I can't find no solution.

    Read the article

  • How does extern work in c++?

    - by symfony
    This is from the <iostream>: namespace std { extern istream cin; ///< Linked to standard input extern ostream cout; ... It seems by using extern the data types defined in other namespaces will just be available?

    Read the article

  • Why wont extern link to a static variable?

    - by Jared P
    Why does extern int n not compile when n is declared (in a different file) static int n, but works when declared int n? (Both of these declarations were at file scope.) Basically, why is int n in file scope not the same as static int n in the same scope? Is it only in relation to extern? If so, what about extern am I missing?

    Read the article

  • extern and global in c

    - by JPro
    Can anyone please tell me is there any special requirement to use either EXTERN or GLOBAL variables in a C program? I do not see any difference in a program like below, if I change from gloabl to extern. #include <stdio.h> #include <stdlib.h> int myGlobalvar = 10; int main(int argc, char *argv[]) { int myFunc(int); int i; i = 12; myGlobalvar = 100; printf("Value of myGlobalvar is %d , i = %d\n", myGlobalvar, i); i = myFunc(10); printf("Value of passed value : %d\n",i); printf("again Value of myGlobalvar is %d , i = %d\n", myGlobalvar, i); system("PAUSE"); return 0; } int myFunc(int i) { i = 20 + 1000; //extern int myGlobalvar; myGlobalvar = 20000; // printf("Value of passed value : %d",i); return i; } If uncomment extern int myGlobalvar, the value does not change. Is there any correct difference between both? Can anyone please correct me?

    Read the article

  • Newbie question: When to use extern "C" { //code } ?

    - by Russel
    Hello, Maybe I'm not understanding the differences between C and C++, but when and why do we need to use: extern "C" { ? Apparently its a "linkage convention"? I read about it briefly and noticed that all the .h header files included with MSVS surround their code with it. What type of code exactly is "C code" and NOT "C++ code"? I thought C++ included all C code? I'm guessing that this is not the case and that C++ is different and that standard features/functions exist in one or the other but not both (ie: printf is C and cout is C++), but that C++ is backwards compatible though the extern "C" declaration. Is this correct? My next question depends on the answer to the first, but I'll ask it here anyway: Since MSVS header files that are written in C are surrounded by extern "C" { ... }, when would you ever need to use this yourself in your own code? If your code is C code and you are trying to compile it in a C++ compiler, shouldn't it work without problem because all the standard h files you include will already have the extern "C" thing in them with the C++ compiler? Do you have to use this when compiling in C++ but linking to alteady built C libraries or something? Please help clarify this for me... Thanks! --Keith

    Read the article

  • Problem with extern keyword in C++

    - by Jeff
    What's the difference between the following two declarations? I thought they were equivalent, but the first sample works, and the second does not. I mean it compiles and runs, but the bitmap display code shows blank. I have not stepped through it yet, but am I missing something obvious? GUI_BITMAP is a simple structure describing a bitmap. This is for VC++ 2005, but I think it fails in VC++ 2008 also. Scratching my head on this one... Sample 1: extern "C" const GUI_BITMAP bmkeyA_cap_active; extern "C" const GUI_BITMAP bmkeyA_cap_inactive; Sample 2: extern "C" { const GUI_BITMAP bmkeyA_cap_active; const GUI_BITMAP bmkeyA_cap_inactive; };

    Read the article

  • extern "C" has no effect in msvc++ 9.0

    - by Dewfy
    I manage project for JNI for both compilers: MSVC++ 8.0 and 9.0, my cpp file contains following implementation: extern "C" { JNIEXPORT jlong JNICALL Java_context_ServiceProviderContext_StartServiceProvider (JNIEnv * env, jclass, jstring jspath){ ..... } With help of depends.exe utility I can see that MSVC 8.0 successfully exports function as it is expected: Java_context_ServiceProviderContext_StartServiceProvider But compiling under MSVC 9.0 gets me crazy it exports like ignoring extern "C" at all. depends.exe shows me: _Java_context_ServiceProviderContext_StartServiceProvider@12 Does anybody know what exactly in 9.0 project that causes this behavior?

    Read the article

  • extern(al) problem

    - by Knowing me knowing you
    Why can't I compile this code? //main #include "stdafx.h" #include "X.h" #include "Y.h" //#include "def.h" extern X operator*(X, Y);//HERE ARE DECLARED EXTERNAL *(X,Y) AND f(X) extern int f(X); /*GLOBALS*/ X x = 1; Y y = x; int i = 2; int _tmain(int argc, _TCHAR* argv[]) { i + 10; y + 10; y + 10 * y; //x + (y + i); x * x + i; f(7); //f(y); //y + y; //106 + y; return 0; } //X struct X { int i; X(int value):i(value) { } X operator+(int value) { return X(i + value); } operator int() { return i; } }; //Y struct Y { int i; Y(X x):i(x.i) { } Y operator+(X x) { return Y(i + x.i); } }; //def.h int f(X x); X operator*(X x, Y y); //def.cpp #include "stdafx.h" #include "def.h" #include "X.h" #include "Y.h" int f(X x) { return x; } X operator*(X x, Y y) { return x * y; } I'm getting err msg: Error 2 error LNK2019: unresolved external symbol "int __cdecl f(struct X)" Error 3 error LNK2019: unresolved external symbol "struct X __cdecl operator*(struct X,struct Y)" Another interesting thing is that if I place the implementation in def.h file it does compiles without errs. But then what about def.cpp? Why I'm not getting err msg that function f(X) is already defined? Here shouldn't apply ODR rule. Second concern I'm having is that if in def.cpp I change the return type of f from int to double intelliSense underlines this as an error but program still compiles? Why?

    Read the article

  • How does an "extern C" declaration work?

    - by samoz
    I'm taking a programming languages course and we're talking about the "extern C" declaration. How does this declaration work at a deeper level other than "it interfaces C and C++"? How does this affect the bindings that take place in the program as well?

    Read the article

  • problem with extern variable

    - by sksingh73
    I have got 2 cpp files & a header file, which I have included in both cpp files. It's like this: abc.h extern uint32_t key; a.cpp #include "abc.h" uint32_t key; int main { ............. } b.cpp #include "abc.h" int main { printf("Key: %.8x\n", key); ............. } Now when I compile a.cpp, there is no error. but when i compile b.cpp it gives error "undefined reference to `key'". Please help me in finding the problem in this code.

    Read the article

  • C++: namespace conflict between extern "C" and class member

    - by plaisthos
    Hi, I stumbled upon a rather exotic c++ namespace problem: condensed example: extern "C" { void solve(lprec * lp); } class A { public: lprec * lp; void solve(int foo); } void A::solve(int foo) { solve(lp); } I want to call the c function solve in my C++ member function A::solve. The compiler is not happy with my intent: error C2664: 'lp_solve_ilp::solve' : cannot convert parameter 1 from 'lprec *' to 'int' Is there something I can prefix the solve function with? C::solve does not work

    Read the article

  • C++: namespace conflicht between extern "C" and class member

    - by plaisthos
    Hi, I stumbled upon a rather exotic c++ namespace problem: condensed example: extern "C" { void solve(lprec * lp); } class A { public: lprec * lp; void solve(int foo); } void A::solve(int foo) { solve(lp); } I want to call the c funcition solve in my C++ member function A::solve. The compiler is not happy with my intents: error C2664: 'lp_solve_ilp::solve' : cannot convert parameter 1 from 'lprec *' to 'int' Is there something I can prefix the solve function? C::solve does not work

    Read the article

  • gcc does not resolve extern global variables, with or without -c option

    - by Moons
    Hello everyone! So i have this issue : i am declaring some extern global variables in my C program. If I don't use the -c option for gcc, i get undefined references errors. But with that -c option, the linking is not done, which means that i don't have an executable generated. So how do I solve this? Here is my makefile. As I am not good with writing makefiles, I took one from another project then I changed a few things. So maybe I'm missing something here. # Makefile calculPi INCL = -I$(INCL_DIR) DEFS = -D_DEBUG_ CXX_FLAGS =-g -c -lpthread -lm CXX = gcc $(CXX_FLAGS) $(INCL) $(DEFS) LINK_CXX = gcc OBJ = approx.o producteur.o sequentialApproximation.o main.o LINKOBJ = approx.o producteur.o sequentialApproximation.o main.o BIN = calculPi.exe RM = rm -fv all: calculPi.exe clean: ${RM} *\~ \#*\# $(OBJ) clean_all: clean ${RM} $(BIN) cleanall: clean ${RM} $(BIN) $(BIN): $(OBJ) $(CXX) $(LINKOBJ) -o "calculPi.exe" main.o: main.c $(CXX) main.c -o main.o $(CXX_FLAGS) approx.o: approx.c approx.h $(CXX) -c approx.c -o approx.o $(CXX_FLAGS); producteur.o: producteur.c producteur.h $(CXX) -c producteur.c -o producteur.o $(CXX_FLAGS); sequentialApproximation.o : sequentialApproximation.c sequentialApproximation.h $(CXX) -c sequentialApproximation.c -o sequentialApproximation.o $(CXX_FLAGS);

    Read the article

  • Why do you need "extern C" for in C++ callbacks to C functions?

    - by Artyom
    Hello, I find such examples in Boost code. namespace boost { namespace { extern "C" void *thread_proxy(void *f) { .... } } // anonymous void thread::thread_start(...) { ... pthread_create(something,0,&thread_proxy,something_else); ... } } // boost Why do you actually need this extern "C"? It is clear that thread_proxy function is private internal and I do not expect that it would be mangled as "thread_proxy" because I actually do not need it mangled at all. In fact in all my code that I had written and that runs on may platforms I never used extern "C" and this had worked as-as with normal functions. Why extern "C" is added? My problem is that extern "C" function pollute global name-space and they do not actually hidden as author expects. This is not duplicate! I'm not talking about mangling and external linkage. It is obvious in this code that external linkage is unwanted!

    Read the article

  • C# extern int ? How do I make a global var across classes and namespaces ?

    - by dr d b karron
    Dear C#'ers; As an old C/C++ programmer, I want to keep a global int counter across all of MY namespaces and classes. Public static extern int EventCount; Is not working; the VS2010 compiler won't let me have an extern int. Even with a DLLImport. [DllImport ( "SilverlightApplication37.dll" )] public static extern int EventCount; VS2010 complains Error 1 The modifier 'extern' is not valid for this item so how do i have a global int across all my code ? Cheers! dr.K

    Read the article

  • Why do you need "extern C" for C++ callbacks to C functions?

    - by Artyom
    Hello, I find such examples in Boost code. namespace boost { namespace { extern "C" void *thread_proxy(void *f) { .... } } // anonymous void thread::thread_start(...) { ... pthread_create(something,0,&thread_proxy,something_else); ... } } // boost Why do you actually need this extern "C"? It is clear that thread_proxy function is private internal and I do not expect that it would be mangled as "thread_proxy" because I actually do not need it mangled at all. In fact in all my code that I had written and that runs on may platforms I never used extern "C" and this had worked as-as with normal functions. Why extern "C" is added? My problem is that extern "C" function pollute global name-space and they do not actually hidden as author expects. This is not duplicate! I'm not talking about mangling and external linkage. It is obvious in this code that external linkage is unwanted! Answer: Calling convention of C and C++ functions are not necessary the same, so you need to create one with C calling convention. See 7.5 (p4) of C++ standard.

    Read the article

  • What is the Effect of Declaring 'extern "C"' in the Header to a C++ Shared Library?

    - by Adam
    Based on this question I understand the purpose of the construct in linking C libraries with C++ code. Now suppose the following: I have a '.so' shared library compiled with a C++ compiler. The header has a 'typedef stuct' and a number of function declarations. If the header includes the extern "C" declaration... #ifdef __cplusplus extern "C" { #endif // typedef struct ...; // function decls #ifdef __cplusplus } #endif ... what is the effect? Specifically I'm wondering if there are any detrimental side effects of that declaration since the shared library is compiled as C++, not C. Is there any reason to have the extern "C" declaration in this case?

    Read the article

  • Question with "extern" in C

    - by why
    When programming, I would like to split one large file(which contains main function) to many small files, so there is one common case: functions in small files can modify the var from main file, so i think extern is very useful! for instance: in main.c extern int i = 100; in small.c extern int i; fprintf(stdout, "var from main file: %d\n", i); I just want to know is my understanding right?

    Read the article

  • aligning extern constants (gcc)

    - by ~buratinas
    I want to make some static constants globally visible. I'm pretty familiar how to do that in C++. The problem is that these constants need to be aligned to some exotic boundary. Do I have to specify the alignment in extern declaration? I'm using GCC4.5 in *.cpp file static const constant_t constant __attribute__((aligned(64))) = {blah,blah,blah}; in *.h file //Which one is correct? extern const constant_t constant; extern const constant_t constant __attribute__((aligned(64)));

    Read the article

  • Data transfer is extrem slow after partitioning extern usb drive

    - by user125912
    I bought an extern usb 3.0 drive with 500 gb capacity. OS is Windows 7. I use it with an usb 2.0 slot, no prob. Initially I used it without making several partitions and it was fast as hell. Then I had the great idea to make partitions, one for programs, one for data and one for backup. I chose the free EASEUS Partition Master 9.1.1. and ended up with these partitions: F:Apps, primary, NTFS, 100gb H:Data, logic, NTFS, 250gb B:Backup, logic, NTFS, 150gb THE PROBLEM: When I copy files from C: to F: I get a transfer rate of about 100 KB/S ! When I copy files from C: to H: I get a transfer rate of about 4 MB/S ! thats all muuuch to slow, slower then before. What can I do to speed the shit up? Thanks in advance!

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >