...

/

Why do we need attributes?

Why do we need attributes?

In this part we learn about attributes!

Let’s start with an example

Have you ever used __declspec, __attribute or #pragma directives in your code?

Here is an example:

Press + to interact
// set an alignment
struct S { short f[3]; } __attribute__ ((aligned (8)));
// this function won't return
void fatal () __attribute__ ((noreturn));

Or for DLL import/export in MSVC:

Press + to interact
#if COMPILING_DLL
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT __declspec(dllimport)
#endif

Those are existing ...