Need help understanding odd C++ semantic

Started by
2 comments, last by Servant of the Lord 11 years ago

Hi, I have a basic understanding of C++, but when I examine real-world code I still encounter lots of confusing bits and pieces. For example, this class declaration from the Ogre 3D source:

class _OgreExport Root : public Singleton<Root>

{

...

What is _OgreExport?

Thanks!

Advertisement

_OgreExport is probably some weird #define the Ogre team made.

Yep, it is. You can see it in action here. That is where they defined it.

Basically in C++ there is something called the preprocessor, it's what deals with all the lines that start with # like #include or #define. At the simplest level, it replaces the Macro with the defined value.

In this case, it's to handle the various platforms. For example, for Android:

204 #if OGRE_PLATFORM == OGRE_PLATFORM_ANDROID
205 # define _OgreExport
It has no value. Meaning that when compiled for Android, the value _OgreExport will be replaced with an empty value.
While later on down, you can see if Ogre is being compiled as a DLL, it gets a different value:
156 # else
157 # if defined( OGRE_NONCLIENT_BUILD )
158 # define _OgreExport __declspec( dllexport )
159 # else
In this case, your code to the compiler will appear as:
class __declspec( dllexport) Root: public Sin.....
Make sense?

And __declspec( dllexport) is a non-standard (i.e. compiler specific) feature in Microsoft's compilers. There's some information here on it.

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!

__declspec (dllexport) works with GCC also, when compiling on Windows.

This topic is closed to new replies.

Advertisement