5 ms·
The zpl_u64 seems to be because they're trying to support older versions of the MSVC compiler[1]. As for why they're using a signed size parameter, I'm not real
by messe 6y ago
The zpl_u64 seems to be because they're trying to support older versions of the MSVC compiler[1]. As for why they're using a signed size parameter, I'm not really sure. One idiom they appear to use often is[2]:
for (...; x--; y++)
where x is a size-type of some kind. They may be defaulting to signed size types to avoid errors in case somebody decides to change to above to:
for (...; x-- >= 0; y++)
There's even a macro zpl_size_of:
#define zpl_size_of(x) (zpl_isize)(sizeof(x))
But the real weirdness is in the other macros:
#define cast(Type) (Type)
...just why? And
#define ZPL_MULTILINE(...) #__VA_ARGS__
is supposed to be a way of having multiline literals in C. But, everything inside the "..." has to be valid C tokens. It might work as a string literal in many cases, but it's misleading at best and broken at worst.
I'm not sure what the advantage of the following is vs. just setting the bits using & and | which every C programmer should already be familiar with:
#define ZPL_MASK_SET(var, set, mask) \
do { \
if (set) \
(var) |= (mask); \
else \
(var) &= ~(mask); \
} while (0)
There's surely no excuse for this:
#define zpl_global static // Global variables
While a lot of the library looks useful, stuff like the above makes it feel like it's written by somebody who knows C, but doesn't feel fully comfortable writing it.
[1]: https://github.com/zpl-c/zpl/blob/master/code/header/essentials/types.h#L11-L40 https://github.com/zpl-c/zpl/blob/master/code/header/essenti...
[2]: https://github.com/zpl-c/zpl/blob/27c80bd5807da5238777bfcba8588731b77683cc/code/source/hashing.c#L136 https://github.com/zpl-c/zpl/blob/27c80bd5807da5238777bfcba8...
- up2isomorphism 6y agoThese extra wrappers are most likely when library writer trying to cover windows platform, which has almost never been a good place for ANSI C programming.
- keldaris 6y ago> There's surely no excuse for this The "excuse" is greppability since static has three completely different meanings in C and the desire to clearly denote global variables is fairly common. The same reasoning goes for the cast define as well. Whether you find value in these small abuses of the preprocessor depends on your coding habits, but I don't really see much reason to criticize them. If the author finds them helpful, what's the harm? There isn't much room for confusion and they're not forced on the users of the library.