This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] Define wordsize.h macros everywhere
- From: Joseph Myers <joseph at codesourcery dot com>
- To: Steve Ellcey <sellcey at caviumnetworks dot com>
- Cc: <libc-alpha at sourceware dot org>, <ynorov at caviumnetworks dot com>
- Date: Wed, 26 Oct 2016 20:06:55 +0000
- Subject: Re: [PATCH] Define wordsize.h macros everywhere
- Authentication-results: sourceware.org; auth=none
- References: <1477506839.26691.5.camel@caviumnetworks.com>
On Wed, 26 Oct 2016, Steve Ellcey wrote:
> diff --git a/bits/wordsize.h b/bits/wordsize.h
> index 9ef0e85..2ebecd6 100644
> --- a/bits/wordsize.h
> +++ b/bits/wordsize.h
> @@ -1 +1,28 @@
> #error "This file must be written based on the data type sizes of the target"
> +
> +/* The following entries are a template for what defines should be in the
> + wordsize.h header file for a target. */
> +
> +/* Bits per word (size of CPU register). */
> +#define __WORDSIZE
That's not an accurate description. It's definitely the size of long int
and pointers, even if registers are larger.
> +/* Set to the size of the f_fsid field in the statvfs and statvfs64 structs.
> + In most cases this is the same as __WORDSIZE but some 32 bit hosts may set
> + it to 64. */
> +#define __SYSCALL_WORDSIZE
If it's so specific to those syscalls, it doesn't belong in
bits/wordsize.h but in some header specific to those syscalls. Even the
*concept* of syscalls doesn't belong in bits/wordsize.h (remember there
are non-syscall ports such as Hurd).
> +/* Set to 1 if ssize_t is type 'unsigned long' instead of type 'unsigned int'
> + so that SIZE_MAX is defined as an unsigned long constant instead of an
> + unsigned int constant. Set to 0 if ssize_t is 'unsigned int'. */
> +#define __WORDSIZE32_SIZE_ULONG
Is this about ssize_t as the comment says (twice), or size_t?
> +/* Set to 1 if ptrdiff_t is type 'long' instead of type 'int' so that
> + PTRDIFF_MIN and PTRDIFF_MAX are defined as long constants instead of
> + int constants. Set to 0 if ptrdiff_t is type 'int'. */
> +#define __WORDSIZE32_PTRDIFF_LONG
For both these macros I think consensus is as Andreas said in
<https://sourceware.org/ml/libc-alpha/2016-07/msg00251.html> and
<https://sourceware.org/ml/libc-alpha/2016-07/msg00267.html>.
That is, they should only be defined if __WORDSIZE == 32. They should be
tested with #if not #ifdef, but all such tests should only be evaluated if
__WORDSIZE == 32, so that we get -Wundef errors if any such test gets
evaluated with __WORDSIZE == 64.
So the comments specifying the semantics of those macros should say that
they are only defined or used if __WORDSIZE == 32, and the headers should
only define them under that condition.
--
Joseph S. Myers
joseph@codesourcery.com