bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: examples/loadables/getconf.c


From: Eric Blake
Subject: Re: examples/loadables/getconf.c
Date: Fri, 05 Oct 2012 10:50:08 -0600
User-agent: 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 5.2.4.2.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:

http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_372

Symbolic Constant
An object-like macro defined with a constant value.
Unless stated otherwise, the following shall apply to every symbolic
constant:
• 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>
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html#tag_13_23_03_06
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

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]