Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Macro before class name

Tags:

c++

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 ... ?)

like image 748
SnuKies Avatar asked Jul 28 '16 09:07

SnuKies


People also ask

What is __ FILE __ in C?

__FILE__ This macro expands to the name of the current input file, in the form of a C string constant. This is the path by which the preprocessor opened the file, not the short name specified in ' #include ' or as the input file name argument. For example, "/usr/local/include/myheader.

What is __ function __ in C++?

(C++11) The predefined identifier __func__ is implicitly defined as a string that contains the unqualified and unadorned name of the enclosing function. __func__ is mandated by the C++ standard and is not a Microsoft extension.

What is a macro in C++?

Macros and its types in C/C++ A macro is a piece of code in a program that is replaced by the value of the macro. Macro is defined by #define directive. Whenever a macro name is encountered by the compiler, it replaces the name with the definition of the macro.


1 Answers

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

like image 62
Rotem Avatar answered Oct 11 '22 23:10

Rotem