Search code examples
cgrpc-c++

What's the effect of empty macro `GRPCAPI` before gRPC function declaration?


When I read the code in gRPC, I found many APIs using GRPCAPI as qualifier.

GRPCAPI grpc_channel* grpc_cronet_secure_channel_create(
    void* engine, const char* target, const grpc_channel_args* args,
    void* reserved);

When I click the link to GRPCAPI, it's an empty macro.

#ifndef GPRAPI
#define GPRAPI
#endif

#ifndef GRPCAPI
#define GRPCAPI GPRAPI
#endif

I understand some usages of empty macro:

  • preventing multiple copies of the same header being included
  • used as a switch for debug or removing sensitive code

But here the GRPCAPI belongs to neither. Is it just a marker to tell us the function is an API? Or more effect for document or others functions?


Solution

  • I really appreciate the answer from @Raildex and comment from @paulsm4, which are very inspiring.

    But the exactly function of GRPCAPI and GPRAPI is used to mark APIs as a label.

    There is a script in grpc named list_api.py using the label GPRAPI and GRPCAPI, which is the only place using these two labels.

    _RE_API = r'(?:GPRAPI|GRPCAPI|CENSUSAPI)([^;]*);'
    
    for m in re.finditer(_RE_API, text):   # match file content
    ...
    

    After running the script, we'll get:

    ...
    - arguments: void* engine, const char* target, const grpc_channel_args* args, void*
        reserved
      header: include/grpc/grpc_cronet.h
      name: grpc_cronet_secure_channel_create
      return_type: grpc_channel*
    ...