Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Fri, 17 Apr 2015 12:50:49 -0400
From: Rich Felker <>
Subject: Re: Explicit casts in ctype.h suppress compiler warnings

On Fri, Apr 17, 2015 at 01:59:14PM +0300, Alexander Monakov wrote:
> For the following erroneous source code:
> #include <ctype.h>
> int f(char *c)
> {
>   return isdigit(c) || isspace(c);
> }
> GCC warns only for passing a pointer to isspace; isdigit is implemented as a
> macro that casts its argument to unsigned, and the warning is suppresed
> because the origin of the cast is in a system header.  Since isspace is
> implemented with a static inline helper function, there is a warning.  With
> glibc headers, no warning is issued in either case for a similar reason.
> I think it would be nice if musl's ctype.h could aid the compiler in
> diagnosing erroneous use, like it happens today for only for isspace() of all
> macros declared there.  The cost of restructuring the header to achieve that
> does not seem too high.  Thoughts?

Do you have an idea in mind for how we could achieve that? I suspect
the macros are still better optimizable than the inline function
approach, so I'd lean towards doing a macro that avoids evaluating c
and just checks its type, which would involve using ?: I think.


Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.