__STRICT_ANSI__ problems in math.h
Jeff Johnston
jjohnstn@redhat.com
Thu Jul 12 17:49:00 GMT 2007
Patch checked in.
-- Jeff J.
Jeff Johnston wrote:
> Jevin,
>
> Your check matches what the system features.h uses. There is a bit
> more sorting required though because there is some non-C99 stuff thrown
> in here and there. Take a look at the attached patch.
>
> Anybody, did I miss anything?
>
> -- Jeff J.
>
> Sweval, Jevin A wrote:
>> Currently math.h checks to make sure that __STRICT_ANSI__ is not
>> defined before prototyping functions like fmax. This is presumably to
>> ensure that non-C89 functions are not defined if -ansi is passed to
>> gcc. However, __STRICT_ANSI__ is still defined when passing -std=c99
>> to gcc. This causes C99 functions like fmax to not have any
>> prototypes. It seems that checking for __STRICT_ANSI__ is not enough.
>> Perhaps a solution is to check for __STRICT_ANSI__ and a
>> __STDC_VERSION__ >= 199901L? This isn't a problem for me with GCC
>> 3.4.4 on Cygwin because GCC has a builtin fmax, but with GCC 3.3.3
>> Cygwin, the compiled code fails to work correctly because of the lack
>> of prototypes. Below is an example of what I am talking about. I'm
>> guessing that there are more instances of this type of C89 checking,
>> but I didn't have to worry about them for the scope of my problem.
>>
>> -Jevin Sweval
>>
>> original math.h
>> ================================================
>> #endif /* ! defined (_REENT_ONLY) */
>>
>> #if !defined(__STRICT_ANSI__) || defined(__cplusplus)
>>
>> /* ISO C99 types and macros. */
>>
>> #ifndef FLT_EVAL_METHOD
>> ================================================
>>
>> correct(?) checking:
>> ================================================
>> #endif /* ! defined (_REENT_ONLY) */
>>
>> #if !defined(__STRICT_ANSI__) || defined(__cplusplus) ||
>> __STDC_VERSION__ >= 199901L
>>
>> /* ISO C99 types and macros. */
>>
>> #ifndef FLT_EVAL_METHOD
>> ================================================
>>
>> ****************************************************************************************
>>
>>
>> Note: If the reader of this message is not the intended recipient, or
>> an employee or agent responsible for delivering this message to the
>> intended recipient, you are hereby notified that any dissemination,
>> distribution or copying of this communication is strictly prohibited.
>> If you have received this communication in error, please notify us
>> immediately by replying to the message and deleting it from your
>> computer. Thank you.
>> ****************************************************************************************
>>
>
>
> ------------------------------------------------------------------------
>
> Index: math.h
> ===================================================================
> RCS file: /cvs/src/src/newlib/libc/include/math.h,v
> retrieving revision 1.27
> diff -u -p -r1.27 math.h
> --- math.h 17 May 2007 18:50:56 -0000 1.27
> +++ math.h 5 Jul 2007 19:05:04 -0000
> @@ -1,4 +1,5 @@
> #ifndef _MATH_H_
> +
> #define _MATH_H_
>
> #include <sys/reent.h>
> @@ -109,7 +110,7 @@ extern double fmod _PARAMS((double, doub
> #endif /* ! defined (__math_68881) */
> #endif /* ! defined (_REENT_ONLY) */
>
> -#if !defined(__STRICT_ANSI__) || defined(__cplusplus)
> +#if !defined(__STRICT_ANSI__) || defined(__cplusplus) || __STDC_VERSION__ >= 199901L
>
> /* ISO C99 types and macros. */
>
> @@ -231,15 +232,6 @@ extern double fdim _PARAMS((double, doub
> extern double fmax _PARAMS((double, double));
> extern double fmin _PARAMS((double, double));
> extern double fma _PARAMS((double, double, double));
> -extern void sincos _PARAMS((double, double *, double *));
> -
> -/* GNU extensions */
> -# ifndef exp10
> -extern double exp10 _PARAMS((double));
> -# endif
> -# ifndef pow10
> -extern double pow10 _PARAMS((double));
> -# endif
>
> #ifndef __math_68881
> extern double log1p _PARAMS((double));
> @@ -251,32 +243,17 @@ extern double acosh _PARAMS((double));
> extern double atanh _PARAMS((double));
> extern double remainder _PARAMS((double, double));
> extern double gamma _PARAMS((double));
> -extern double gamma_r _PARAMS((double, int *));
> extern double lgamma _PARAMS((double));
> -extern double lgamma_r _PARAMS((double, int *));
> extern double erf _PARAMS((double));
> extern double erfc _PARAMS((double));
> -extern double y0 _PARAMS((double));
> -extern double y1 _PARAMS((double));
> -extern double yn _PARAMS((int, double));
> -extern double j0 _PARAMS((double));
> -extern double j1 _PARAMS((double));
> -extern double jn _PARAMS((int, double));
> #define log2(x) (log (x) / M_LOG2_E)
>
> #ifndef __math_68881
> extern double hypot _PARAMS((double, double));
> #endif
>
> -extern double cabs();
> -extern double drem _PARAMS((double, double));
> -
> #endif /* ! defined (_REENT_ONLY) */
>
> -#endif /* !defined (__STRICT_ANSI__) || defined(__cplusplus) */
> -
> -#if !defined(__STRICT_ANSI__) || defined(__cplusplus)
> -
> /* Single precision versions of ANSI functions. */
>
> extern float atanf _PARAMS((float));
> @@ -305,10 +282,6 @@ extern float sqrtf _PARAMS((float));
> extern float fmodf _PARAMS((float, float));
> #endif /* ! defined (_REENT_ONLY) */
>
> -#endif /* !defined(__STRICT_ANSI__) || defined(__cplusplus) */
> -
> -#ifndef __STRICT_ANSI__
> -
> /* Other single precision functions. */
>
> extern float exp2f _PARAMS((float));
> @@ -341,39 +314,66 @@ extern float rintf _PARAMS((float));
> extern float scalbnf _PARAMS((float, int));
> extern float log1pf _PARAMS((float));
> extern float expm1f _PARAMS((float));
> -extern void sincosf _PARAMS((float, float *, float *));
> -
> -/* GNU extensions */
> -# ifndef exp10f
> -extern float exp10f _PARAMS((float));
> -# endif
> -# ifndef pow10f
> -extern float pow10f _PARAMS((float));
> -# endif
>
> #ifndef _REENT_ONLY
> extern float acoshf _PARAMS((float));
> extern float atanhf _PARAMS((float));
> extern float remainderf _PARAMS((float, float));
> extern float gammaf _PARAMS((float));
> -extern float gammaf_r _PARAMS((float, int *));
> extern float lgammaf _PARAMS((float));
> -extern float lgammaf_r _PARAMS((float, int *));
> extern float erff _PARAMS((float));
> extern float erfcf _PARAMS((float));
> +#define log2f(x) (logf (x) / (float) M_LOG2_E)
> +extern float hypotf _PARAMS((float, float));
> +#endif /* ! defined (_REENT_ONLY) */
> +
> +#endif /* !defined (__STRICT_ANSI__) || defined(__cplusplus) || __STDC_VERSION__ >= 199901L */
> +
> +#if !defined (__STRICT_ANSI__) || defined(__cplusplus)
> +
> +extern double cabs();
> +extern double drem _PARAMS((double, double));
> +extern void sincos _PARAMS((double, double *, double *));
> +extern double gamma_r _PARAMS((double, int *));
> +extern double lgamma_r _PARAMS((double, int *));
> +
> +extern double y0 _PARAMS((double));
> +extern double y1 _PARAMS((double));
> +extern double yn _PARAMS((int, double));
> +extern double j0 _PARAMS((double));
> +extern double j1 _PARAMS((double));
> +extern double jn _PARAMS((int, double));
> +
> +extern float cabsf();
> +extern float dremf _PARAMS((float, float));
> +extern void sincosf _PARAMS((float, float *, float *));
> +extern float gammaf_r _PARAMS((float, int *));
> +extern float lgammaf_r _PARAMS((float, int *));
> +
> extern float y0f _PARAMS((float));
> extern float y1f _PARAMS((float));
> extern float ynf _PARAMS((int, float));
> extern float j0f _PARAMS((float));
> extern float j1f _PARAMS((float));
> extern float jnf _PARAMS((int, float));
> -#define log2f(x) (logf (x) / (float) M_LOG2_E)
> -extern float hypotf _PARAMS((float, float));
>
> -extern float cabsf();
> -extern float dremf _PARAMS((float, float));
> +/* GNU extensions */
> +# ifndef exp10
> +extern double exp10 _PARAMS((double));
> +# endif
> +# ifndef pow10
> +extern double pow10 _PARAMS((double));
> +# endif
> +# ifndef exp10f
> +extern float exp10f _PARAMS((float));
> +# endif
> +# ifndef pow10f
> +extern float pow10f _PARAMS((float));
> +# endif
>
> -#endif /* ! defined (_REENT_ONLY) */
> +#endif /* !defined (__STRICT_ANSI__) || defined(__cplusplus) */
> +
> +#ifndef __STRICT_ANSI__
>
> /* The gamma functions use a global variable, signgam. */
> #ifndef _REENT_ONLY
More information about the Newlib
mailing list