In article <bn************@ID-114079.news.uni-berlin.de>,
Jeremy Yallop <je****@jdyallop.freeserve.co.uk> wrote:
Looking over some code I came across a line like this
if isalnum((unsigned char)c) {
which was accepted by the compiler without complaint. Should the
compiler have issued a diagnostic in this case? (I think it's not
required to, but I'd like confirmation).
isalnum probably expands to something that's wrapped with parens.
F'rexample, on a random system readily accessible to me:
--------
dave@hct-cvs:~/clc (0) $ cat jy-for-syntax-expand-isalnum.c
#include <ctype.h>
#include <stdio.h>
#define STR(x) STR_(x)
#define STR_(x) #x
int main(void)
{
printf("isalnum(x) expands to %s\n",STR(isalnum(x)));
return 0;
}
dave@hct-cvs:~/clc (0) $ gcc -W -Wall -ansi -pedantic -O -c jy-for-syntax-expand-isalnum.c
dave@hct-cvs:~/clc (0) $ ./a.out
isalnum(x) expands to (__ctype_b[(int) ((x))] & (unsigned short int) _ISalnum)
dave@hct-cvs:~/clc (0) $
--------
so "if isalnum(foo)" would be expanded to
"if (expansion_of_isalnum_with_parens)", which is valid.
If this weren't the case it would be, if I'm not mistaken, a syntax
error that requires a diagnostic. GCC appears to agree with me:
--------
dave@hct-cvs:~/clc (0) $ cat jy-for-syntax-broken-if.c
int bogus_function(int);
#include <stdio.h>
int main(void)
{
if bogus_function(42)
{
puts("bogus_function() returned nonzero");
}
return 0;
}
dave@hct-cvs:~/clc (0) $ gcc -W -Wall -ansi -pedantic -O -c jy-for-syntax-broken-if.c
jy-for-syntax-broken-if.c: In function `main':
jy-for-syntax-broken-if.c:7: parse error before `bogus_function'
jy-for-syntax-broken-if.c:10: warning: control reaches end of non-void function
dave@hct-cvs:~/clc (1) $
--------
dave
--
Dave Vandervies
dj******@csclub.uwaterloo.ca
Have some pride, you're a physics major! You know deep in your heart
you're better than the rest of the slobs there, you should be able to
knock this course off easily. --Brian B. Rodenborn in comp.lang.c