SnuKies
SnuKies

Reputation: 1723

Macro before class name

I was recently looking over some code and I've stumble upon this:

class IDATA_EXPORT IData {
    /* .... */
}

Where IDATA_EXPORT is not more than :

#ifndef IDATA_EXPORT
    #define IDATA_EXPORT
#endif

What is IDATA_EXPORT in this case? (I mean, is it type like int, char etc ... ?)

Upvotes: 14

Views: 4373

Answers (1)

Rotem
Rotem

Reputation: 21947

Most likely at some point in time, or under some conditions it was defined as (for example, under MSVC):

#define IDATA_EXPORT __declspec(dllexport)

Which was used to indicate the classes to publicly export from the library.

Using the macro, the developer could alternate between exporting classes and not exporting anything, without having to go over each individual class.

This is often part of a macro pattern which alternates between importing and exporting classes, depending on whether the code is compiled from the library, or from a program dependent on the library. It would then look something like:

#ifdef IS_LIBRARY // <--this would only be defined when compiling the library!
   #define IDATA_EXPORT __declspec(dllexport)  
#else
   #define IDATA_EXPORT __declspec(dllimport)  
#endif

For more information, see dllexport, dllimport on MSDN

Upvotes: 15

Related Questions