|
Can you explain these macros ? #define StringZ(Z) {sizeof(Z) - 1, (u8 *)(Z)}
#define StringZFunc(Z) BundleString(sizeof(Z) - 1, (Z)) |
Answered by
bagaffey
Sep 13, 2025
Replies: 1 comment
|
Yes, those functions are basically initializing the string (alias buffer) struct without copying anything. typedef struct buffer
{
umw Count; // strength length
u8* Data; // the string data
} buffer, string;StringZ is creating the struct initialization at compile time. This should only be used for literals. I am actually going to rename this now to make it clearer. Both simply take a string argument. One should be used for literals while the other could be used for runtime strings. The Z in the name is to indicate that it handles zero-terminated strings, that means a string that is terminated C-style with a null at the end The length that is calculated is the logical length. |
0 replies
Answer selected by
btgvesta
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, those functions are basically initializing the string (alias buffer) struct without copying anything.
So, this:
StringZ is creating the struct initialization at compile time. This should only be used for literals. I am actually going to rename this now to make it clearer.
StringZFunc creates it at runtime because there is a function call happening.
Both simply take a string argument. One should be used for literals while the other could be used for runtime strings.
The Z in the name is to indicate that it handles zero-terminated strings, that means a string that is termin…