This is the mail archive of the
mailing list for the glibc project.
Re: Patch for locale/programs/3level.h
> From: Bruno Haible <email@example.com>
> Date: Tue, 7 Aug 2001 16:39:13 +0200 (CEST)
> I have learned to avoid negative numbers in all expression that
> involve unsigned integer types.
What gave you that impression? Negative numbers are the most commonly
used method that works in general. This is the method used in the C
and POSIX standards, for example; these standards are chock-full of
expressions like (size_t) -1 and (uid_t) -1.
> + /* Marker for an empty slot. This has the value 0xFFFFFFFF, regardless
> + whether 'int' is 16 bit, 32 bit, or 64 bit. */
> + #define EMPTY ((uint32_t) ~0)
This expression assumes twos-complement arithmetic. It won't work on
a ones-complement host, since EMPTY will evaluate to zero on such a host.
If you insist on using ~0 you should comment this portability
restriction somewhere. But it's clearer if you replace ~0 with -1;
that avoids the need for the comment, and (more important) it is
more-easily understood by people who are familiar with the programming
standards. I see no need to invent a separate, less-portable style
for this concept.