1

I found that macro in vulcan.h file (The Vulcan API header file). How should I understand it?

#define VK_DEFINE_HANDLE(object) typedef struct object##_T* object; 

Especially what the double hash is for?

How it differs compared to (different asterisk position):

#define VK_DEFINE_HANDLE(object) typedef struct object##_T *object;

I know that it is struct type definition but where is a body of that struct?

TSr
  • 331
  • 1
  • 12
  • 1
    The position of the asterisk shouldn't matter, if that's what you're asking. As for the `##`, that just concatenates the value of `object` with the fixed string `_T`. So if `object` is `xyz`, you get `xyz_T`. – Tom Karzes Feb 26 '16 at 17:29
  • 1
    The real point is that this is a technique to allow types checking for void or generic pointers. As the macro says it declares handles that are normally declared as `void *thishandle` or `void *thathandle`. Now if you exchange them in your code the compiler will issue no errors or warning. The technique is to not use void pointers, but pointers to incomplete structures. This way you still can't access the handle data, but the compiler can perform type checking. The macro is an automation for that use. – Frankie_C Feb 26 '16 at 17:36
  • @Frankie_C thanks for this explanation. Very useful for me. – TSr Feb 26 '16 at 19:58

1 Answers1

4

The ## is preprocessor concatenation. It is building a new token from the object macro formal name.

So VK_DEFINE_HANDLE(foo) might be (and probably is, unless foo_T or foo is expanded to something else) expanded to

typedef struct foo_T *foo;

Probably something else (perhaps some other macro expansion) is defining struct foo_T

Read the documentation of the C preprocessor, e.g. of GNU cpp

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547