This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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: Unreviewed math builtins patch (3x)


Hi Harti,

Harti Brandt wrote:
> No. It is annoying enough that warnings are given for names like exp
> and sin. These names should be reserved (and warned about) only if the
> appropriate header file is included.

This is an urband legend: annoying only to people who have never
seen the warning, and the GCC maintainers that have to correct them.


Please read GCC's documentation of -Wshadow and -ffreestanding.


The only time GCC ever (or has ever) warned about a declaration of
the identifiers "exp" or "sin" is

[1] When declared at global scope with external linkage and with a
different prototype to that expected (i.e. a function taking a single
"double" argument and returning a "double" result), where the "_exp"
and  "_sin" symbols will clash/conflict with those provided by the
standard C library.  This warning indicates non-conformant behaviour,
using a C90 reserved indentifier for a different use, and can eaily be
turned off using -ffreestanding.  -ffreestanding instructs the compiler
not to rely upon or worry about the standard libraries.

This warning reflects a real bug in the code.  Other library functions
in libc or libm, such as "printf", may try and call either "exp" or "sin"
with very unexpected results.


[2] When the user specifically uses the -Wshadow command line option.
This is not enabled by default nor by -W or -Wall, that requests the
compiler indicate declarations that "shadow" definitions given at
lower scopes.  i.e. the user has asked to be warned that sin or exp is
being used as a local variable.  If this isn't the required behaviour,
remove the explicit -Wshadow from the command-line.


Finally, if a GCC builtin, such as sin or exp, ever causes problem for
such non-conformant and non-portable code, but the user still wants the
performance advantages of all the other GCC builtins, it is possible to
disable it selectively using -fno-builtin-exp and/or -fno-builtin-sin.
But as explained in [1], misuse of such global identifiers may de-stablize
the system.


Unless this rumour/myth is stamped out soon,  we'll have to add some form
of the above response to the non-bugs section of the compiler's manuals.

Roger
--
Roger Sayle,                         E-mail: roger@eyesopen.com
OpenEye Scientific Software,         WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833


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