Translating C precompiler macros to D

solidstate1991 laszloszeremi at outlook.com
Wed Nov 8 20:43:21 UTC 2023


Here's this precompiler macro from Pipewire, on which many 
important inline functions depend on, like this one:

```c
/**
  * Invoke method named \a method in the \a callbacks.
  * The \a method_type defines the type of the method struct.
  * Returns true if the method could be called, false otherwise.
  */
#define spa_callbacks_call(callbacks,type,method,vers,...)			\
({										\
	const type *_f = (const type *) (callbacks)->funcs;			\
	bool _res = SPA_CALLBACK_CHECK(_f,method,vers);				\
	if (SPA_LIKELY(_res))							\
		_f->method((callbacks)->data, ## __VA_ARGS__);			\
	_res;									\
})
```

So far, the only way out I see is to turn it into a string mixin. 
(SPA_LIKELY is just a needless precompiler macro for labeling 
things.)


More information about the Digitalmars-d-learn mailing list