Вопрос

So I am wondering what a #define foo(bar) does. It seems to have an argument, but no body. Let me give you some context:

Definition

#ifndef __success
    #define __nvapi_success
    #define __success(epxr)
#endif

Usage

#define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl

In the end, NVAPI_INTERFACE is used for function declarations, like so:

NVAPI_INTERFACE NvAPI_Initialize();

This is all taken from NVAPI, Nvidia's Core SDK that I am trying to figure out.

Это было полезно?

Решение

A macro with "no body" (no replacement list) simply has empty body. This means that every "invocation" of that macro in the code will be replaced with an empty sequence of tokens, i.e. the references to that macro will simply disappear without any effect.

In your above example the authors of the code simply wanted all invocations of __success(epxr) to just disappear from the code under certain circumstances (i.e. if __success was not defined previously). That's all there is to it.

The same is true for __nvapi_success macro. I.e. whether your macro has arguments or not does not make any difference in this regard.

Under some other circumstances this macro might get defined differently, with non-empty replacement list. If you look through the rest of the source code you might discover other places that define __success(epxr) differently and conditions, under which it happens.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top