Here is the macro:
#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.
Thread overview | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
September 20 C to D: please help translate this weird macro | ||||
---|---|---|---|---|
| ||||
Here is the macro:
I'm trying to translate the Nuklear GUI library to D here. |
September 20 Re: C to D: please help translate this weird macro | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ki Rill | On Wednesday, 20 September 2023 at 13:53:08 UTC, Ki Rill wrote: >Here is the macro:
I'm trying to translate the Nuklear GUI library to D here. Here is how
|
September 20 Re: C to D: please help translate this weird macro | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ki Rill | On Wednesday, 20 September 2023 at 13:55:14 UTC, Ki Rill wrote: >On Wednesday, 20 September 2023 at 13:53:08 UTC, Ki Rill wrote: >Here is the macro:
I'm trying to translate the Nuklear GUI library to D here. Here is how
Looks like you are not the only one who has issue with them: |
September 20 Re: C to D: please help translate this weird macro | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ki Rill | On Wednesday, 20 September 2023 at 13:53:08 UTC, Ki Rill wrote: >Here is the macro:
I'm trying to translate the Nuklear GUI library to D here. 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/ |
September 20 Re: C to D: please help translate this weird macro | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ki Rill | On Wednesday, 20 September 2023 at 13:55:14 UTC, Ki Rill wrote: >On Wednesday, 20 September 2023 at 13:53:08 UTC, Ki Rill wrote: >Here is the macro:
I'm trying to translate the Nuklear GUI library to D here. Here is how
NK_OFFSETOF is the same as D's struct NK_CONTAINER_OF should probably be translated to:
PS. I did not invent this. My original idea was far worse than this. - It was suggested on IRC by a much cleverer D programmer than myself - Herringway@IRC |
September 21 Re: C to D: please help translate this weird macro | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dejan Lekic | On Wednesday, 20 September 2023 at 17:14:41 UTC, Dejan Lekic wrote: >[...] NK_CONTAINER_OF should probably be translated to:
PS. I did not invent this. My original idea was far worse than this. - It was suggested on IRC by a much cleverer D programmer than myself - Herringway@IRC Thanks! I translated it to this originally after looking at the links you've provided:
>
Now, how should I wrap it like a macro? Template mixin? I'm not that familiar with D meta programming... I shall skim through the |
September 21 Re: C to D: please help translate this weird macro | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ki Rill | On Thursday, 21 September 2023 at 02:23:32 UTC, Ki Rill wrote: >wrote: >[...] Translated it to this eventually:
|
September 21 Re: C to D: please help translate this weird macro | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ki Rill | On Thursday, 21 September 2023 at 02:57:07 UTC, Ki Rill wrote: >On Thursday, 21 September 2023 at 02:23:32 UTC, Ki Rill wrote: >wrote: >[...] Translated it to this eventually:
The 1st argument of So reordering to keep type inference of
(Untested) |
September 21 Re: C to D: please help translate this weird macro | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Treleaven | On Thursday, 21 September 2023 at 16:28:25 UTC, Nick Treleaven wrote: >
There's a trailing
|
September 21 Re: C to D: please help translate this weird macro | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Treleaven | On Thursday, 21 September 2023 at 16:28:25 UTC, Nick Treleaven wrote: >(Untested) There might be a |