This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] manual: Rewrite the section on widths of integer types.
- From: Florian Weimer <fweimer at redhat dot com>
- To: Rical Jasan <ricaljasan at pacific dot net>, libc-alpha <libc-alpha at sourceware dot org>
- Cc: Joseph Myers <joseph at codesourcery dot com>, Zack Weinberg <zackw at panix dot com>, Carlos O'Donell <carlos at redhat dot com>, Michael Kerrisk <mtk dot manpages at gmail dot com>
- Date: Thu, 10 Aug 2017 18:32:56 +0200
- Subject: Re: [PATCH] manual: Rewrite the section on widths of integer types.
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=fweimer at redhat dot com
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0C78CD4D84
- References: <20170727122226.9032-1-ricaljasan@pacific.net>
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