-
-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't terminate RGBDS strings with a NUL #505
Comments
AFAIK, Pascal strings store their length in a single byte just before the contents. This has the disadvantage of limiting the maximum length of a string. I'd like to suggest Rust-style strings instead, where strings are essentially manipulated as a pair of (pointer to start, length). Apart from removing the string length limit, this also allows to pass substrings around much more efficiently. |
Okay, I wasn't intending exactly on using a byte, but the more general idea of storing the length separately. Wasn't aware of Rust's behavior, which is basically what I'm shooting for. |
If you're using C99, you can just use a flexible array member to store the data, which makes the Pascal-like approach a lot simpler: struct string {
unsigned length;
char data[];
}; |
The man page mentions that a NUL truncates a string; this is because RGBDS maps transparently to C strings. People may want to use other terminators (hello Pokémon and its $50, though there 0 is a mostly useless char anyways), or just use 0 in the middle of their strings.
Thus, and especially as fixed-size buffers are mostly being used anyways, RGBDS should use Pascal strings instead.
The text was updated successfully, but these errors were encountered: