Recent versions of gcc and clang on Fedora Linux compile the following program without error:
#include <ctype.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
char c = 'a';
if islower(c)
printf("%d", c);
else
printf("%c", c);
return 0;
}
This is with gcc 4.7.2 and clang 3.0. On my Mac, in contrast, both gcc 4.2.1 and Apple clang 4.1 complain about missing parentheses in the “if islower(c)” line, as expected. In all cases, I ran the compilers with “-std=c99”.
Is this a bug in recent versions of gcc and clang, a quirk in the C language, or something else? The C99 standard (http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf p. 133) appears to mandate parentheses around if expressions in all cases.
I just looked through the
ctype.hfile located in/usr/include/ctype.hand found the following definition forislower:Going to the definition for
__isctype()I find:So your code
if islower(c)expands to:Which, as unwind said, added the parenthesis during expansion.