[vlc-devel] [RFC] signed versus unsigned integer types

Rémi Denis-Courmont rdenis at simphalempin.com
Sun Jan 27 16:07:57 CET 2008

Le Saturday 26 January 2008 16:28:31 Rafaël Carré, vous avez écrit :
> I replaced int64_t with uint64_t and int with size_t where it really
> meant to be unsigned.
> Then looking at the compiler warnings, I had to modify
> modules/{access_output,demux,access,mux} , using (size_t)-1 when the
> value -1 has a special meaning, and >= 0 would mean a real value (used
> in some_pointer[value] for example).

This is wrong. Unsigned types should be used when negative values make no 
sense. Whenever -1 is a special error value, ssize_t or int*_t should be used 

That's why read and write are defined as follow:

ssize_t read (int fd, void *buf, size_t len);
ssize_t write (int, const void *buf, size_t len);

> And also add some castings when the value was used in a function
> expecting a signed type (such as lseek(), which we only use with
> SEEK_SET anyway).

Casting from unsigned to signed is useless when unambiguous, such as a 
parameter to a function.

> - Should I verify that when casted to a signed type, the value is still
> positive ? (that would mean the calling function is making bullshit,
> but could help fighting bugs)

No. Waste of time.

> - Is size_t suited for int replacement, or should I use unsigned int ?

That depends on the case, same as read/write.

> - TAB_* macros in vlc_arrays.h use a signed int to count the number of
> elements, should it be switched to size_t ? ( TAB_FIND uses the value -1
> to signify that no value where found in the array, but could use
> (size_t)-1 instead )

Same as read/write.

> - It would be a good idea to fix the few left warnings in src/ and
> compile it with -Werror to catch errors in the core. Do you agree ?

Not at all. Warnings are hint that something is likely wrong. Silencing them 
makes no sense, unless it's actually a proper fix.

Rémi Denis-Courmont
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20080127/fb1dd16c/attachment.sig>

More information about the vlc-devel mailing list