stdio.h patches for g++ -std=c++11

zosrothko zosrothko@orange.fr
Sat May 10 12:49:00 GMT 2014


Hi Corinna

I made an error by following the website I referenced in my previous 
mail. It was stating that snprintf was "c++11 only". So I bougth the 
official  norm of C++ namely -- ISO/IEC 14882-2011-- from the ANSI eShop 
and below are the specifications of the <cstdio> header. So I reworked 
the patch which integrates now in the first block the proper additional 
declarations for

int    _EXFUN(snprintf, (char *__restrict, size_t, const char 
*__restrict, ...)
                _ATTRIBUTE ((__format__ (__printf__, 3, 4))));
int    _EXFUN(vscanf, (const char *, __VALIST)
                _ATTRIBUTE ((__format__ (__scanf__, 1, 0))));
int    _EXFUN(vsnprintf, (char *__restrict, size_t, const char 
*__restrict, __VALIST)
                _ATTRIBUTE ((__format__ (__printf__, 3, 0))));
int    _EXFUN(vsscanf, (const char *__restrict, const char *__restrict, 
__VALIST)
                _ATTRIBUTE ((__format__ (__scanf__, 2, 0))));
int    _EXFUN(vfscanf, (FILE *__restrict, const char *__restrict, __VALIST)
                _ATTRIBUTE ((__format__ (__scanf__, 2, 0))));


Please notice that vfscanf is not part of the ISO/IEC 14882-2011 norm 
but I think it is a mistake. So I put it with the others added declarations.

My apologizes for the noise and overhead of work.

zos


ISO/IEC 14882-2011 chapter 27.9.2
---------------------------------------------------
27.9.2 C library files [c.files]
Macros:
BUFSIZ FOPEN_MAX SEEK_CUR TMP_MAX _IONBF stdout
EOF L_tmpnam SEEK_END _IOFBF stderr
FILENAME_MAX NULL  SEEK_SET _IOLBF stdin

Types: FILE fpos_t size_t <cstdio>

Functions:
clearerr fopen fsetpos putc setbuf vprintf
fclose fprintf ftell putchar setvbuf vscanf
feof fputc fwrite puts snprintf vsnprintf
ferror fputs getc rename sprintf vsprintf
fflush fread getchar remove tmpfile vsscanf
fgetc freopen gets rewind tmpnam
fgetpos fscanf perror scanf ungetc
fgets fseek printf sscanf vfprintf


Le 09/05/2014 16:14, Corinna Vinschen a écrit :
> On May  9 12:01, zosrothko wrote:
>> Corinna
>> Le 09/05/2014 10:43, Corinna Vinschen a écrit :
>>> On May  9 07:52, zosrothko wrote:
>>>> Hi Corinna
>>>>
>>>> I made a typo in my previous patch. Here the corrected one.
>>> Thanks.  Your patches are missing a matching ChangeLog entry, btw.
>>>
>>> However, on second thought I'm not sure that removing the 'i' variations
>>> of the functions from "__cplusplus >= 201103L" in this way is such a
>>> good idea.
>>>
>>> The 'i' functions are a newlib extension for embedded targets.
>>>
>>> They are not part of any standard, so they are certainly neither part
>>> of "__cplusplus >= 201103L", nor part of "__STDC_VERSION__ >= 199901L".
>>>
>>> So, either we remove these functions from both standards, or we include
>>> them in both standards.
>>>
>>> But if we remove them from both standards when will they be defined at
>>> all?  This should be cleared up before making this change.
>>>
>>> Is defining them with only
>>>
>>>    #if !defined(__STRICT_ANSI__)
>>>
>>> sufficient?
>> That won't work because of this
>>
>> $ g++ -xc++ -std=c++11 -dM -E - < /dev/null | sort | grep ANSI
>> #define __STRICT_ANSI__ 1
>>
>> $ g++ -xc++ -std=gnu++11 -dM -E - < /dev/null | sort | grep ANSI
> Are you sure?  Your example seems to indicate that
>
>    #if !defined(__STRICT_ANSI__)
>
> is ok for the 'i' functions.
>
>
> Corinna
>

-------------- next part --------------
Index: newlib/libc/include/stdio.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/stdio.h,v
retrieving revision 1.69
diff -u -r1.69 stdio.h
--- newlib/libc/include/stdio.h	5 May 2014 12:53:47 -0000	1.69
+++ newlib/libc/include/stdio.h	10 May 2014 12:26:10 -0000
@@ -223,6 +223,14 @@
 int	_EXFUN(_rename, (const char *, const char *));
 #endif
 #endif
+int	_EXFUN(snprintf, (char *__restrict, size_t, const char *__restrict, ...)
+               _ATTRIBUTE ((__format__ (__printf__, 3, 4))));
+int	_EXFUN(vscanf, (const char *, __VALIST)
+               _ATTRIBUTE ((__format__ (__scanf__, 1, 0))));
+int	_EXFUN(vsnprintf, (char *__restrict, size_t, const char *__restrict, __VALIST)
+               _ATTRIBUTE ((__format__ (__printf__, 3, 0))));
+int	_EXFUN(vsscanf, (const char *__restrict, const char *__restrict, __VALIST)
+               _ATTRIBUTE ((__format__ (__scanf__, 2, 0))));
 #if !defined(__STRICT_ANSI__) || defined(__USE_XOPEN2K)
 #ifdef _COMPILING_NEWLIB
 int	_EXFUN(fseeko, (FILE *, _off_t, int));
@@ -232,7 +240,7 @@
 off_t	_EXFUN(ftello, ( FILE *));
 #endif
 #endif
-#if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L) || (__cplusplus >= 201103L)
+#if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L)
 #ifndef _REENT_ONLY
 int	_EXFUN(asiprintf, (char **, const char *, ...)
                _ATTRIBUTE ((__format__ (__printf__, 2, 3))));
@@ -259,8 +267,6 @@
                _ATTRIBUTE ((__format__ (__printf__, 2, 3))));
 int	_EXFUN(siscanf, (const char *, const char *, ...)
                _ATTRIBUTE ((__format__ (__scanf__, 2, 3))));
-int	_EXFUN(snprintf, (char *__restrict, size_t, const char *__restrict, ...)
-               _ATTRIBUTE ((__format__ (__printf__, 3, 4))));
 int	_EXFUN(sniprintf, (char *, size_t, const char *, ...)
                _ATTRIBUTE ((__format__ (__printf__, 3, 4))));
 char *	_EXFUN(tempnam, (const char *, const char *));
@@ -278,24 +284,16 @@
                _ATTRIBUTE ((__format__ (__printf__, 2, 0))));
 int	_EXFUN(vfiscanf, (FILE *, const char *, __VALIST)
                _ATTRIBUTE ((__format__ (__scanf__, 2, 0))));
-int	_EXFUN(vfscanf, (FILE *__restrict, const char *__restrict, __VALIST)
-               _ATTRIBUTE ((__format__ (__scanf__, 2, 0))));
 int	_EXFUN(viprintf, (const char *, __VALIST)
                _ATTRIBUTE ((__format__ (__printf__, 1, 0))));
 int	_EXFUN(viscanf, (const char *, __VALIST)
                _ATTRIBUTE ((__format__ (__scanf__, 1, 0))));
-int	_EXFUN(vscanf, (const char *, __VALIST)
-               _ATTRIBUTE ((__format__ (__scanf__, 1, 0))));
 int	_EXFUN(vsiprintf, (char *, const char *, __VALIST)
                _ATTRIBUTE ((__format__ (__printf__, 2, 0))));
 int	_EXFUN(vsiscanf, (const char *, const char *, __VALIST)
                _ATTRIBUTE ((__format__ (__scanf__, 2, 0))));
 int	_EXFUN(vsniprintf, (char *, size_t, const char *, __VALIST)
                _ATTRIBUTE ((__format__ (__printf__, 3, 0))));
-int	_EXFUN(vsnprintf, (char *__restrict, size_t, const char *__restrict, __VALIST)
-               _ATTRIBUTE ((__format__ (__printf__, 3, 0))));
-int	_EXFUN(vsscanf, (const char *__restrict, const char *__restrict, __VALIST)
-               _ATTRIBUTE ((__format__ (__scanf__, 2, 0))));
 #endif /* !_REENT_ONLY */
 #endif /* !__STRICT_ANSI__ */
 


More information about the Newlib mailing list