This is the mail archive of the mailing list for the newlib 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: [Patch] Fix type signature of feof and ferror in c++

On 12/11/2014 12:23 PM, Jonathan Roelofs wrote:

On 12/11/14 10:04 AM, Corinna Vinschen wrote:
On Dec 11 09:08, Jonathan Roelofs wrote:
This fixes one of the libc++ tests: depr/depr.c.headers/stdio_h.pass.cpp
  #ifndef _REENT_SMALL
-#define    feof(p)        __sfeof(p)
-#define    ferror(p)    __sferror(p)
+#define    feof(p)        ((int)__sfeof(p))
+#define    ferror(p)    ((int)__sferror(p))
  #define    clearerr(p)    __sclearerr(p)

Wouldn't it make more sense for all targets to move this into the
definitions of __sfeof/__sferror?
Depends on what the type signature of __sfeof and __sferror are supposed to be... that I don't know. If those are just internal newlib things, then I don't think it really matters, either way would work.
This really is a language-dependent thing. C defines the results of != as being int, so the cast is both superfluous and potentially misleading (from the point of view that its being there implies it is somehow needed), while C++ defines the result as bool (and why the cast is needed to pass the check). This suggests that however it is done it is perhaps worth a comment to point out why the casts are there. (Perhaps something like "/* (int) casts for C++, not needed but do no harm for C */"?)
     The signature should be matching the actual feof() and ferror() functions.

Index: libc/include/stdio.h
RCS file: /cvs/src/src/newlib/libc/include/stdio.h,v
retrieving revision 1.71
diff -u -p -r1.71 stdio.h
--- libc/include/stdio.h    9 May 2014 14:25:32 -0000    1.71
+++ libc/include/stdio.h    11 Dec 2014 17:03:03 -0000
@@ -649,8 +649,8 @@ _ELIDABLE_INLINE int __sputc_r(struct _r

-#define    __sfeof(p)    (((p)->_flags & __SEOF) != 0)
-#define    __sferror(p)    (((p)->_flags & __SERR) != 0)
+#define    __sfeof(p)    ((int)(((p)->_flags & __SEOF) != 0))
+#define    __sferror(p)    ((int)(((p)->_flags & __SERR) != 0))
  #define    __sclearerr(p)    ((void)((p)->_flags &= ~(__SERR|__SEOF)))
  #define    __sfileno(p)    ((p)->_file)

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