[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Fri, 05 Oct 2012 10:50:08 -0600
Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120911 Thunderbird/15.0.1
On 10/05/2012 10:17 AM, Eric Blake wrote:
> On 10/05/2012 10:06 AM, Andreas Schwab wrote:
>> Chet Ramey <address@hidden> writes:
>>> Why would you say there's a restriction against using casts or sizeof in
>>> a macro like this?
>> Because it must expand to a valid preprocessor expression.
> C99 22.214.171.124.1
> Sizes of integer types <limits.h>
> 1. The values given below shall be replaced by constant expressions
> suitable for use in #if preprocessing directives. Moreover, except for
> CHAR_BIT and MB_LEN_MAX, the following shall be replaced by expressions
> that have the same type as would an expression that is an object of the
> corresponding type converted according to the integer promotions.
> <stdint.h> and <limits.h> are the two main headers that are this
> explicit about various macros being suitable for use in preprocessor
> arithmetic, and preprocessor arithmetic cannot use casts or sizeof.
And I think this is a bug in POSIX; POSIX says:
An object-like macro defined with a constant value.
Unless stated otherwise, the following shall apply to every symbolic
• It expands to a compile-time constant expression with an integer type.
• It may be defined as another type of constant—e.g., an enumeration
constant—as well as being a macro.
• It need not be usable in #if preprocessing directives.
But nowhere in <limits.h>
does it state that these macros inherited from C99 have the requirement
of also being usable in #if preprocessing.
Eric Blake address@hidden +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Description: OpenPGP digital signature