bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: c-ctype.h calling conventions


From: Bruno Haible
Subject: Re: c-ctype.h calling conventions
Date: Fri, 3 Oct 2008 14:04:56 +0200
User-agent: KMail/1.5.4

Jim Meyering wrote:
> >> set: - use c_isdigit, c_isalpha, c_isalnum directly; no need for casts -
> > Sorry, but I am not sure here. ...
> 
> Oops.  You're right.
> While some of the uses are ok without the cast (i.e., in order),
> others do required it.  So I'll leave the casts.

Good point. I should better document on what you can rely and on what you cannot
rely. Applied this. Now you don't need the casts any more.

Bruno


2008-10-03  Bruno Haible  <address@hidden>

        * lib/c-ctype.h: Add comment.
        Reported by Jim Meyering.

--- lib/c-ctype.h.orig  2008-10-03 14:01:16.000000000 +0200
+++ lib/c-ctype.h       2008-10-03 14:00:17.000000000 +0200
@@ -5,7 +5,7 @@
    <ctype.h> functions' behaviour depends on the current locale set via
    setlocale.
 
-   Copyright (C) 2000-2003, 2006 Free Software Foundation, Inc.
+   Copyright (C) 2000-2003, 2006, 2008 Free Software Foundation, Inc.
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -103,6 +103,21 @@
 
 /* Function declarations. */
 
+/* Unlike the functions in <ctype.h>, which require an argument in the range
+   of the 'unsigned char' type, the functions here operate on values that are
+   in the 'unsigned char' range or in the 'char' range.  In other words,
+   when you have a 'char' value, you need to cast it before using it as
+   argument to a <ctype.h> function:
+
+         const char *s = ...;
+         if (isalpha ((unsigned char) *s)) ...
+
+   but you don't need to cast it for the functions defined in this file:
+
+         const char *s = ...;
+         if (c_isalpha (*s)) ...
+ */
+
 extern bool c_isascii (int c); /* not locale dependent */
 
 extern bool c_isalnum (int c);





reply via email to

[Prev in Thread] Current Thread [Next in Thread]