c++ stuff/OpenGL

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 tells the compiler to ignore what you are calling (if it hasnt been defined yet) as it will be defined later on (you hope).

So you probably arent defining your functions before you are calling them.

yeah plain extern just tells the compiler to trust me that what I’m referring to exists, it will just be up to the linker to decide; but what does

extern “C”

do. i see it from time to time and have no idea what it’s for.

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.

void myFunc(const StructType & s) { … }

Lot’s of good C++ info here:

No no no… you got it almost wrong :stuck_out_tongue:

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?

This link will help you understand the problem: