3

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

Ekta
  • 41
  • 5
  • 2
    You already understand why these might be used but without them actually being defined as something (rather than nothing) we are as much in the dark as you. – Richard Critten Jun 28 '21 at 07:02
  • common header for library and consumer of library. One is exporting function other importing functions. Macros are just helping distinguish those scenarios. – Marek R Jun 28 '21 at 07:03
  • Reopened. The quesiton specifically mentions it's **not** for DLL's, so don't close it as a duplicate assuming it **is** for DLL's. – MSalters Jun 28 '21 at 07:09
  • `I am looking at a C++ code` Where? Let us look to! Why not post a link? `looks like this` We can't guess from "looks like this" what _real_ code is meant to be. Post the real code. – KamilCuk Jun 28 '21 at 07:11
  • Are those the exact macro names used in code? – HolyBlackCat Jun 28 '21 at 07:12
  • *"this is not [for dlls]"* How do you know? – HolyBlackCat Jun 28 '21 at 07:13
  • 1
    Any author wrote macros into a function declaration to conveniently add something to that declaration (e.g. declspec's or attributes). These macros are currently unused i.e. expand to nothing. IMHO, the author could've left a comment how these are intended to be used. As it is it's just a riddle... ;-) – Scheff's Cat Jun 28 '21 at 08:42

2 Answers2

0

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.

MSalters
  • 173,980
  • 10
  • 155
  • 350
0

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.

Mircea Ispas
  • 20,260
  • 32
  • 123
  • 211