Quantcast
Channel: User HolyBlackCat - Stack Overflow
Viewing all articles
Browse latest Browse all 1287

Answer by HolyBlackCat for Why does SDL_RWFromConstMem() size need type int instead of unsigned int?

$
0
0

Even if a value can't be negative, it doesn't necessarily mean you should use an unsigned type for it. The main benefit they have is ability to store larger positive values, but the downside is that some arithmetic operators behaving unintuitively on them. Because of this, some programmers try to avoid unsigned types altogether when possible.

The real problem isn't that it's not unsigned it, the problem is that it's not 64 bit wide on 64-bit platforms, where you can realistically have memory blocks longer than 2gb or 4gb (as representable by 32-bit int and unsigned int respectively).

The fix is to use size_t or its signed counterpart (ptrdiff_t).

And it seems they did exactly that in SDL3: https://wiki.libsdl.org/SDL3/SDL_IOFromConstMem (which wasn't released yet).


Viewing all articles
Browse latest Browse all 1287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>