C to D: please help translate this weird macro

ryuukk_ ryuukk.dev at gmail.com
Wed Sep 20 14:14:58 UTC 2023


On Wednesday, 20 September 2023 at 13:53:08 UTC, Ki Rill wrote:
> Here is the macro:
>
> ```C
> #define NK_CONTAINER_OF(ptr,type,member)\
>     (type*)((void*)((char*)(1 ? (ptr): &((type*)0)->member) - 
> NK_OFFSETOF(type, member)))
> ```
>
> I'm trying to translate the Nuklear GUI library to D 
> [here](https://github.com/rillki/nuklear-d/tree/nuklear-d-translation).

My workflow when trying to port weird C code to D is to have a 
small C file, put an example code, and then run the preprocessor, 
and try to get how things are expanded

Alternatively, latest version of visual studio allows you to see 
that in real time, you'll still have to write example code tho

https://devblogs.microsoft.com/cppblog/visualize-macro-expansion-for-c/


More information about the Digitalmars-d-learn mailing list