From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/7415 Path: news.gmane.org!not-for-mail From: Morten Welinder Newsgroups: gmane.linux.lib.musl.general Subject: Re: Explicit casts in ctype.h suppress compiler warnings Date: Fri, 17 Apr 2015 22:03:53 -0400 Message-ID: References: <1429289394.7038.3.camel@inria.fr> <20150417165238.GA6817@brightrain.aerifal.cx> <20150417213602.GF6817@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: ger.gmane.org 1429322652 22613 80.91.229.3 (18 Apr 2015 02:04:12 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 18 Apr 2015 02:04:12 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-7428-gllmg-musl=m.gmane.org@lists.openwall.com Sat Apr 18 04:04:08 2015 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1YjI75-0005rS-9S for gllmg-musl@m.gmane.org; Sat, 18 Apr 2015 04:04:07 +0200 Original-Received: (qmail 30164 invoked by uid 550); 18 Apr 2015 02:04:05 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 30143 invoked from network); 18 Apr 2015 02:04:04 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=GdYqC9N9E3btKFXTDayKKq1DtNUDmHpLWuktXnzU7TM=; b=tW8AA8e2zTR/BFvmTP0Fj91eYryt4g6yGjY1tq9YmiFo5aGzJZnJ0YVA4x1cnm0e1w Cy0IqK2SM15OEcCHFsoYg7XFl/49Dow6ksgPnCnbIfMpGjDhBG+N8LmKD9ez+Qfak0I3 nGoYyYubB/FaiQ+ewY9kGkTQguhUi58VKAHudz0W/SD4ymAff1FMHgzIwQVQstlRpmG5 9terg2JTu/bFV7dSWQImMDPgqeoodmH2CDhVO/5TEtH5pB/Brecvq/gua+DGGPSakCfm UEZyfuRnQGZSNVlhP06Nic7aw3s/VshMQBobnmtcJGFDGbgcdmfLocHZ/vHZZLo3TjSq cyoQ== X-Received: by 10.107.4.196 with SMTP id 187mr7802336ioe.6.1429322633229; Fri, 17 Apr 2015 19:03:53 -0700 (PDT) In-Reply-To: <20150417213602.GF6817@brightrain.aerifal.cx> Xref: news.gmane.org gmane.linux.lib.musl.general:7415 Archived-At: Ideally isspace and friends should also cause a warning if called with a "char" or "signed char" argument. Such calls are generally wrong unless the range of the argument can somehow be controlled. ("char" might be unsigned, for example.) The number of people who have no idea why they should not make such calls is astounding. The typical response is to blame the compiler and add an (int) cast. The search at https://searchcode.com/?q=isspace+%28int%29 claims ~55k instances. Ignore the first page which is finding isspace implementations, but incorrect uses. M. On Fri, Apr 17, 2015 at 5:36 PM, Rich Felker wrote: > On Fri, Apr 17, 2015 at 09:24:09PM +0300, Alexander Monakov wrote: >> > 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. >> >> I admit I was thinking of doing isspace-style inlines everywhere, but thanks >> to your suggestion I was able to come up with this: >> >> static __inline void __is_int(int a) {} >> #define isdigit(a) (__is_int(0?(a):0), ((unsigned)(a)-'0') < 10) > > This still depends on the inline function getting honored, and puts > extra crap in the debug output. Instead, how about: > > #define isdigit(a) (0 ? (isdigit)(a) : ((unsigned)(a)-'0') < 10) > > Rich