Bug 3439 - math.h, fenv.h macros do not conform to C99
Summary: math.h, fenv.h macros do not conform to C99
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: math (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-10-31 19:42 UTC by Paul Eggert
Modified: 2016-05-08 14:15 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments
fix math.h, fenv.h macros to be usable in #if (3.88 KB, patch)
2006-10-31 19:43 UTC, Paul Eggert
Details | Diff
fix math.h, fenv.h macros to be usable in #if (without removing enums) (2.96 KB, patch)
2006-11-11 01:01 UTC, Paul Eggert
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Eggert 2006-10-31 19:42:08 UTC
In
<https://www.opengroup.org/sophocles/show_mail.tpl?CALLER=index.tpl&source=L&listname=austin-group-l&id=9979>
Geoff Clare reported that the glibc implementations of <math.h> and
<fenv.h> do not conform to C99 or to POSIX, because they define some
macros using techniques that do not work inside #if, but C99 and POSIX
require that the macros work in #if.

I'll attach a patch against glibc head.
Comment 1 Paul Eggert 2006-10-31 19:43:37 UTC
Created attachment 1395 [details]
fix math.h, fenv.h macros to be usable in #if
Comment 2 Ulrich Drepper 2006-11-10 16:24:04 UTC
I don't want to change this.  It's a pointless requirement which just makes it
harder to debug programs since the macros might not be available in the debug info.
Comment 3 Paul Eggert 2006-11-11 01:01:37 UTC
Created attachment 1411 [details]
fix math.h, fenv.h macros to be usable in #if (without removing enums)

Here is a revised patch.  This keeps the enums, so ordinary gcc -g compiles
will have the names in the debug symbol table.	This should overcome the
objection to the original patch.
Comment 4 Ulrich Drepper 2007-02-17 08:59:26 UTC
That is just calling for trouble.  The requirement is unnecessary and most
probably just an oversight.  It makes no sense to have these as macros.  The
best way is to change the requirement in the spec so that this desease isn't
spreading  further.
Comment 5 Joseph Myers 2012-04-27 10:47:50 UTC
Reopening.  We discussed this on #glibc last night.  We want a fix that avoids duplicating the numeric value of each macro; that is, something along the lines of (inside the enum):

#define __FE_WHATEVER 0x100
  FE_WHATEVER = __FE_WHATEVER,
#define FE_WHATEVER __FE_WHATEVER
Comment 6 Andreas Jaeger 2012-04-27 11:23:09 UTC
Check <bits/confname.h> as well, it does the enum like:

    _PC_MAX_CANON,
#define _PC_MAX_CANON                   _PC_MAX_CANON

this should work similar for fenv.h
Comment 7 Andreas Jaeger 2012-04-27 11:41:30 UTC
ignore my last comment, I see the difference...
Comment 8 Paul Eggert 2012-04-28 23:15:42 UTC
How about this instead?

          FE_WHATEVER =
  #define FE_WHATEVER 0x100
          FE_WHATEVER,

This repeats the number just once and the identifier just thrice,
with no need for __FE_WHATEVER.  It's odd, but I've seen odder.
Comment 9 jsm-csl@polyomino.org.uk 2012-04-29 00:12:48 UTC
I think that would be fine as well.
Comment 10 Joseph Myers 2012-11-02 22:15:11 UTC
math.h fixed, following the approach suggested in comment 8, by:

commit 0155d5b26e32b2012d9f1842c3b06324746d3087
Author: Joseph Myers <joseph@codesourcery.com>
Date:   Fri Nov 2 22:11:21 2012 +0000

    Make math.h FP_* macros usable in #if (bug 3439).

fenv.h still needs fixing.
Comment 11 Joseph Myers 2012-11-03 17:09:45 UTC
fenv.h fixed for 2.17 by:

commit fbeafedeea37e0af1984a6511018d159f5ceed6a
Author: Joseph Myers <joseph@codesourcery.com>
Date:   Sat Nov 3 17:07:56 2012 +0000

    Make fenv.h FE_* macros usable in #if (bug 3439).