Subject: isspace and compiler warnings
To: None <>
From: Greg Troxel <>
List: tech-userlevel
Date: 10/18/2006 08:42:57

In ufraw (pkgsrc/graphics/gimp-ufraw), I see warnings:

ufraw_routines.c:262: warning: array subscript has type 'char'
ufraw_routines.c:263: warning: array subscript has type 'char'

These are from the following code, which passes a 'const gchar' to

  void conf_parse_text(GMarkupParseContext *context, const gchar *text, gsize len,
          gpointer user, GError **error)
      conf_data *c = user;
      const gchar *element = g_markup_parse_context_get_element(context);
      char temp[max_path];
      int i;
      error = error;
      for(; len>0 && isspace(*text); len--, text++);
      for(; len>0 && isspace(text[len-1]); len--);

man isspace says that it is a function taking an int.
But, our implementation is a macro, so promotion doesn't happen and
the warning occurs due to the expansion.

Inside __BEGIN_DECLS, we have

int	isspace(int);

and then

#define	isspace(c)	((int)((_ctype_ + 1)[(c)] & _S))

So, is the ufraw code above wrong?   If so, should I cast to int?  Do
I need to verify that the gchar is positive?  Or is casting to int a
do-no-harm since promotion would happen were this a real function?
Or is our macro implementation wrong because it doesn't have the same
semantics (including warnings) as the C99/POSIX-specified function?
I see at that macros
are explicitly allowed.

Content-Type: application/pgp-signature

Version: GnuPG v1.4.5 (NetBSD)