This is the mail archive of the newlib@sourceware.org mailing list for the newlib 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: Use of #if DEBUG in reent.h


On 01/04/2017 04:14 AM, Freddie Chopin wrote:
> Hi!
> 
> Maybe it would be ok to change the offending line to:
> 
> #if defined(DEBUG) && DEBUG != 0
> 
> This way the old behaviour should be retained in most of the cases.
>>From what I've read, if you add "-DDEBUG" to GCC flags, it is
> equivalent to "-DDEBUG=1".

Not by my experience.  There's a difference to being defined to the
empty string (-DDEBUG on the command line corresponds to '#define DEBUG'
in source) vs. an explicit string (-DDEBUG=1 corresponds to '#define
DEBUG 1').

' I also think that any undefined macro in a
> "#if whatever" statement is considered to be 0, but this is also only a
> GCC extensions.

No, it is required by the C standard.  Any otherwise-unknown
preprocessor token is required to be treated as 0 in arithmetic context.
 However, based on your choice of warning flags, gcc can treat such
usage as a preprocessor error.  Therefore, it is indeed safest to check
whether a macro is defined before coercing it into an arithmetic value,
when writing headers that must be robust to various choices of compiler
warning flags.  Gcc also has a pragma for marking a particular header as
a system header (which, among other things, silences warnings about
constructs in that header that would normally provoke warnings, such as
the implicit use of an undefined macro name meaning 0).

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


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