weird struct definition

I am deciphering someone else's code which contains the following block (in an .h file)

struct QD_API qd_real {
double x[4]; /* The Components. */

qd_real();
qd_real(const char *s);
qd_real(const dd_real &dd);
qd_real(double d);
qd_real(int i);
}

What does this code actually declare? I don't understand why there are two names after struct. This does not seem as an example of inheritance. I've looked around but did not find any help on such a weird usage.
Search in the headers for something like #define QD_API xxxx
It would be a specifier or an attribute that can be applied to a class.

For example,
1
2
3
4
5
6
7
8
struct alignas(16) qd_real
{
    double x[4]; /* The Components. */

    qd_real();

    // ...
};


can also be written as:
1
2
3
4
5
6
7
8
9
10
#define QD_ALIGN alignas(16)

struct QD_ALIGN qd_real
{
    double x[4]; /* The Components. */

    qd_real();

    // ...
};
Thanks, this clarifies it, in fact the code contains

1
2
3
#ifndef QD_API
#define QD_API /**/
#endif 


must be an architecture dependent parameter
This kind of defines is usually for building a dll. The thing is that depending on whether you are building the dll itself or using it - you need to declare functions/classes as __declspec(dllexport) and __declspec(dllimport) respectively. To keep the same header file for both versions, you include for example the following preprocessor construction:

1
2
3
4
5
#ifdef QD_EXPORTING
	#define QD_API __declspec(dllexport)
#else
	#define QD_API __declspec(dllimport)
#endif 


and then you define QD_EXPORTING when building dll.

The example in your case is probably for case of building a static library, or direct use of code.

Topic archived. No new replies allowed.