[PATCH] Fix some stdlib.h functions under __STRICT_ANSI__ and/or -std=c99

Jon TURNEY jon.turney@dronecode.org.uk
Wed Oct 24 09:06:00 GMT 2012


The C99 functions strtoll and strtoull are not declared in stdlib.h when using
gcc -std=c99, as they are under !__STRICT_ANSI__.

The C99 functions strtof and strtold are declared in stdlib.h even when
__STRICT_ANSI__ is defined.

Attached is a patch to put these declarations under !defined(__STRICT_ANSI__)
|| (__STDC_VERSION__ >= 199901L).

$ cat c99-stdlib-test.c
#include <stdlib.h>

int main()
{
  strtoll("1234", NULL , 0);
  strtoull("1234", NULL, 0);
  strtof("1234", NULL);
  /* only available on platforms where long double equals double... */
  /* strtold("1234", NULL); */
  return 0;
}

before patch:

$ gcc c99-stdlib-test.c -std=c99 -Werror=implicit-function-declaration
c99-stdlib-test.c: In function ‘main’:
c99-stdlib-test.c:7:3: error: implicit declaration of function ‘strtoll’
c99-stdlib-test.c:8:3: error: implicit declaration of function ‘strtoull’

after patch:

$ gcc c99-stdlib-test.c -std=c99 -Werror=implicit-function-declaration

$ gcc c99-stdlib-test.c -std=c89 -Werror=implicit-function-declaration
c99-stdlib-test.c: In function ‘main’:
c99-stdlib-test.c:7:3: error: implicit declaration of function ‘strtoll’
c99-stdlib-test.c:8:3: error: implicit declaration of function ‘strtoull’
c99-stdlib-test.c:9:3: error: implicit declaration of function ‘strtof’

newlib/ChangeLog:

2012-10-19  Jon TURNEY  <jon.turney@dronecode.org.uk>

	* libc/include/stdlib.h (strtof, strtoll, strtoull, strtold):Prototype
	if not __STRICT_ANSI__ or stdc version C99 or greater.

-------------- next part --------------
Index: newlib/libc/include/stdlib.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/stdlib.h,v
retrieving revision 1.40
diff -u -p -r1.40 stdlib.h
--- newlib/libc/include/stdlib.h	19 Jul 2010 18:21:11 -0000	1.40
+++ newlib/libc/include/stdlib.h	19 Oct 2012 15:44:43 -0000
@@ -125,7 +125,9 @@ _PTR	_EXFUN(reallocf,(_PTR __r, size_t _
 _VOID	_EXFUN(srand,(unsigned __seed));
 double	_EXFUN(strtod,(const char *__n, char **__end_PTR));
 double	_EXFUN(_strtod_r,(struct _reent *,const char *__n, char **__end_PTR));
+#if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L)
 float	_EXFUN(strtof,(const char *__n, char **__end_PTR));
+#endif
 #ifndef __STRICT_ANSI__
 /* the following strtodf interface is deprecated...use strtof instead */
 # ifndef strtodf 
@@ -186,9 +188,17 @@ long long _EXFUN(atoll,(const char *__np
 long long _EXFUN(_atoll_r,(struct _reent *, const char *__nptr));
 long long _EXFUN(llabs,(long long));
 lldiv_t	_EXFUN(lldiv,(long long __numer, long long __denom));
+#endif /* ! __STRICT_ANSI__ */
+#if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L)
 long long _EXFUN(strtoll,(const char *__n, char **__end_PTR, int __base));
+#endif
+#ifndef __STRICT_ANSI__
 long long _EXFUN(_strtoll_r,(struct _reent *, const char *__n, char **__end_PTR, int __base));
+#endif /* ! __STRICT_ANSI__ */
+#if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L)
 unsigned long long _EXFUN(strtoull,(const char *__n, char **__end_PTR, int __base));
+#endif
+#ifndef __STRICT_ANSI__
 unsigned long long _EXFUN(_strtoull_r,(struct _reent *, const char *__n, char **__end_PTR, int __base));
 
 #ifndef __CYGWIN__
@@ -217,7 +227,9 @@ _VOID	_EXFUN(__eprintf,(const char *, co
 
 /* On platforms where long double equals double.  */
 #ifdef _LDBL_EQ_DBL
+#if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L)
 extern long double strtold (const char *, char **);
+#endif
 extern long double wcstold (const wchar_t *, wchar_t **);
 #endif /* _LDBL_EQ_DBL */
 



More information about the Newlib mailing list