Use of #if DEBUG in reent.h

Jeff Johnston jjohnstn@redhat.com
Mon Jan 9 23:25:00 GMT 2017


Patch attached.  I will check in if no objections.  It was only used for
debugging the _REENT_CHECK macros so I renamed it _REENT_CHECK_DEBUG.

-- Jeff J.

----- Original Message -----
> Hmm, I appear to have put that code in ages ago (2008) because it originally
> had asserts in
> place by default from code changes in 2002.  Not sure anyone ever used this.
> 
> I think the choice of DEBUG was unfortunate and non-standard so, yes,
> I think renaming it makes sense with at least an under-score.  The flag was
> meant to be a switch, opposite to NDEBUG to turn on use of the asserts so
> #ifdef should be used.  I will post a patch shortly.
> 
> -- Jeff J.
> 
> ----- Original Message -----
> > Jeff?
> > 
> > Thanks,
> > Corinna
> > 
> > On Jan  3 16:41, Joe Seymour wrote:
> > > Users can enable assertions in newlib/libc/include/sys/reent.h by
> > > defining the macro DEBUG. As DEBUG is a relatively obvious and general
> > > purpose name, it is also used by other projects. I've seen it used by
> > > the Atmel Software Framework (ASF) and some TI Energia projects.  A web
> > > search finds a few more examples:
> > > 
> > > https://forum.pjrc.com/threads/19916-reent-h-space-problems-or-just-my-pc
> > > http://forum.arduino.cc/index.php?topic=151655.0
> > > 
> > > Actually, these are all examples of projects that have been seen to fail
> > > to build with the following error:
> > > 
> > > > include\sys\reent.h:458:10: error: #if with no expression
> > > 
> > > This occurs when DEBUG is defined but has no value. Which seems to
> > > happen with the following test case:
> > > 
> > > > #define DEBUG
> > > > #include <sys/reent.h>
> > > 
> > > Notably, I don't see an error if I remove the #define and instead pass
> > > -DDEBUG (with no value) to my gcc build [msp430-elf-gcc (GCC) 7.0.0
> > > 20161220].
> > > 
> > > My initial reaction to seeing the error message was that this was a bug
> > > in reent.h, which should use #ifdef DEBUG instead. Unfortunately if you
> > > do that then "#define DEBUG 0" and -DDEBUG=0 result in debug being
> > > turned on, which seems undesirable. This leads me to believe that the
> > > use of #if DEBUG is deliberate and not considered a bug?
> > > 
> > > I mention this here because I couldn't find any previous discussion of
> > > it on this list, and as it has been discussed elsewhere I think there's
> > > value in having a definitive statement about it here.
> > > 
> > > Again for the record, I'll ask whether "#if DEBUG" could be changed to
> > > "#if _SYS_REENT_H_DEBUG", or similar? That would avoid the error and the
> > > naming conflict.  I'm assuming that the examples listed above aren't
> > > trying to turn newlib assertions on. I suspect that at the very least
> > > DEBUG has been used for long enough that there's a stronger argument for
> > > keeping it the same than for changing it to something else?
> > > 
> > > Thanks,
> > > 
> > > Joe Seymour
> > 
> > --
> > Corinna Vinschen
> > Cygwin Maintainer
> > Red Hat
> > 
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Fix-sys-reent.h-to-remove-use-of-DEBUG-flag.patch
Type: text/x-patch
Size: 1091 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/newlib/attachments/20170109/aaf9e75c/attachment.bin>


More information about the Newlib mailing list