Interfacing with C libs: weeding through C/C++ macros and such in header files
Alec Stewart
alec-stewart at protonmail.com
Sun Jan 13 22:40:57 UTC 2019
Hello all!
So while I have a decent grasp on D, I've been having trouble
figuring out specific projects that I could do in D, so I thought
I'd maybe find a little C or C++ library I could transfer over to
D. I decided to make my life easier and look for something that's
just a single header file, and while that does make things easier
there are a TON of macros and inline functions that it almost
seems ridiculous and it's somewhat overwhelming.
Example without code; for some reason a macro is defined for the
stdlib functions `malloc`, `realloc`, and `free`. Maybe it's just
because I don't have any pro experience with C or C++, but that
seems a bit excessive. Or I could just be dumb.
Example with code (because I need help figuring out how whether I
even need this or not):
#ifndef RS_API
#ifdef RS_NOINLINE
/* GCC version 3.1 required for the no inline attribute. */
#if RS_GCC_VERSION > 30100
#define RS_API static __attribute__((noinline))
#elif defined(_MSC_VER)
#define RS_API static __declspec(noinline)
#else
#define RS_API static
#endif
#elif RS_C99
#define RS_API static inline
#elif defined(__GNUC__)
#define RS_API static __inline__
#elif defined(_MSC_VER)
#define RS_API static __forceinline
#else
#define RS_API static
#endif
#endif
I understand what it's doing, but do I really any of this with D?
And then there's this inline function
#define RS_DATA_SIZE(f, s, input)
\
do {
\
if (rs_is_heap(input)) \
f(s, input->heap.buffer, rs_heap_len(input)); \
else \
f(s, input->stack.buffer, rs_stack_len(input)); \
} while (0)
so yea. There's a little over 300 lines of preprocessor stuff. My
question is how you all determine what to carry over from C libs
in terms of preprocessor stuff. I imagine most useful values
everyone just makes an enum for, and structs and unions are kept.
Thanks for any help you give!
More information about the Digitalmars-d-learn
mailing list