working with making an opengl dll for win32, I find the functions will not properly export unless I put
extern “C”
in front of their declarations in the dll’s .h file. why is this; what does extern “C” do to functions? is it a link thing?
also, is there really any difference between calling by reference and passing a pointer (other than a missing asterisk or ampersand in one case or the other) to functions? I call a function that draws my vertex arrays by passing a pointer to a structure; would I gain anything by using a reference or not using pointer arguments at all?
extern “C” specifies that the function or variable should use C linkage rather than C++ linkage. it’s usually used when mixing C and C++ to allow the use of C headers within a C++ program.
Using & (reference) and * (pointer) is the same thing, the generated machine code is usually identical, the reson for it’s existence is that it had to be added to make the operator overloading to work.
Prefer references to pointers where possible. If you use a pointer, make it a class member that gets allocated (new()'d) in the constructor and delete()'d in the destructor to avoid memory leaks.
Also, pass by const reference if you aren’t modifying the structure in the function.
Anyways, what extern C does is tells the compiler to look for the function in C terms. For example, in C
double sqrt(double) is called sqrt internally. in C++ the same thing ends up being __double_sqrt because of name beautification (helps not with OPERATOR overloading, but FUNCTION overloading).
Don’t confuse this with functions inside classes, where the function has a refrence to the class prepended to the argument list, as well as all the name beautification.
As far as pass by refrence or pass by ptr, well, I usually pass by ptr (99% of the time) because Im used to working with pointers. Heh, mebbe its cause im an old C dog.
[This message has been edited by 147-2 (edited 02-26-2003).]
Originally posted by knoxville: I find the functions will not properly export unless I put extern “C”
in front of their declarations in the dll’s .h file.
What kind of code is going to be calling this dll? C or C++ code?