C++ ACCB1 ACCB2

Viewed 81

This is a basic question . Kindly guide me where i should look . I am looking at a C++ code which looks like this

ACCB1 void ACCB2 MyPluginCommand(void *clientData)

When I search for them in the code base I see them to be just

#define ACCB1
#define ACCB2

I understand for dlls we need to specify what all functions we want to expose but this is not that .

I many a times see these kinds of codes but never really understood . For C++ i understand function name , return type and arguments are sufficient . What does these variable helps us and how does compiler treats them

2 Answers

Since you mention this is not for DLLs : It could be used for attributes, such as [[deprecated]].

The idea of that attribute is that the compiler can warn you when you're using a library function for which a better alternative exists.

This is a common pattern used to enable external tools to generate code or do validations. To enable these tools sometimes tags are needed, but these tags shouldn't affect the code.

For example:

#define SERIALIZABLE
...
SERIALIZABLE struct MyStruct
{
    SERIALIZABLE int value = 0;
    int someOtherValue = 0;
};

SERIALIZABLE tag doesn't do anything for the compiler here, but it might enable an external tool that parses this file to generate serialization code for MyStruct and more specifically only for value member from MyStruct. Without the tag it would be very difficult for the tool to know for which type and for which members to generate serialization code.

Obviously one can write by hand the serialization code, but this is boring, takes time and is also error prone.

Considering the name of the function, MyPluginCommand, in this case those tags might be used to generate glue code or adapters for the plugin, but I can't know without more info.

Related