You typically want to use the native integer size for something like this, for the code to be more portable. The native integer size should really be int, but it's not defined as such in the standard. My preference at the moment:
off_t for file offsets
ptrdiff_t for memory offsets (vs. size_t for unsigned)
int for return flags
A problem with this is that printf does not have sizes to match these.
there are also int_least8_t or what ever size and signedness too. or int_fast8_t. You explicitly state I want at least 8 bits or I want at least 8 bits but whatever is fastest.
Fixed sized integers are useful in two situations (that I can think of); if you're interfacing with a language that doesn't use the same integer size as your C compiler, or if you're relying on integers being a certain width (maybe you're casting between integers and non-integers, or writing a certain number of bytes to a binary file).
I doubt either of these situations come up when dealing with line sizes in a text editor.
And a third situation: Writing device drivers interfacing with hardware registers of specific sizes, although you should use `{u}int_least<N>_t` for that, to give the compiler some leeway with alignment.
There are many cases where using fixed size types can save a significant amount of memory (and your application is constrained by memory on some platform) or CPU time (design to minimize cache misses happens all the time in high performance applications like games).
Neither of these situations is happening in a text editor application though.
jhallenworld|9 years ago
off_t for file offsets
ptrdiff_t for memory offsets (vs. size_t for unsigned)
int for return flags
A problem with this is that printf does not have sizes to match these.
kzrdude|9 years ago
See also https://forge.rust-lang.org/platform-support.html
omtose|9 years ago
jwilk|9 years ago
For size_t: "%zu"
There's no format for off_t, though. The best you can do is to typecast it to intmax_t, and then use "%jd".
beached_whale|9 years ago
Sean1708|9 years ago
I doubt either of these situations come up when dealing with line sizes in a text editor.
datenwolf|9 years ago
jstelly|9 years ago
Neither of these situations is happening in a text editor application though.
unknown|9 years ago
[deleted]
wyldfire|9 years ago