This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] manual: Rewrite the section on widths of integer types.


On 07/27/2017 02:22 PM, Rical Jasan wrote:
> +A common reason that a program needs to know how many bits are in an
> +integer type is for using an array of @code{long int} as a bit vector.
> +You can access the bit at index @var{n} with:
> +
> +@smallexample
> +vector[@var{n} / LONGBITS] & (1 << (@var{n} % LONGBITS))
> +@end smallexample
> +
> +@noindent
> +provided you define @code{LONGBITS} as the number of bits in a
> +@code{long int}.

This example should now use ULONG_WIDTH.  The type should be unsigned
long int, and the constant should be 1UL (not 1), to avoid shifting into
the sign position.

Thanks,
Florian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]