为什么 'false' 的类型是 int? (CS50)

why is type of 'false' is int? (CS50)

I would like to exit the program when my argv[1] contains some character other than alphabet. Therefore, I stated:

for(int j = 0, p = strlen(argv[1]); j < p; j++)
    {
        if (false(isalpha(argv[1][j])))
        {
            printf("invalid character\n");
            return 1;
        }
    }

but it says error: called object type 'int' is not a function or function pointer. I don't understand what this means. This was from the CS50 week2's problem - substitution.

C 中没有名为 false 的 built-in 函数。您的表达式 false(isalpha(argv[1][j])) 具有 false(x) 的形式,所以它看起来像一个函数调用。

header <stdbool.h> 定义了一个扩展为整数常量零的宏。所以 false(x) 实际上是 0(x)。其中,0 是一个 int 常量。编译器消息“called object type 'int' is not a function or function pointer”告诉你你不能调用这个 int 0 就好像它是一个函数一样。

如果您的程序中有一些名为 false 的函数,它可能已被包含 <stdbool.h>(或可能是其他 header 文件)有效覆盖。如果是这样,您应该重命名您的函数。

要测试表达式是否为“假”,您可以使用 ! 运算符:

if (!isalpha(argv[1][j]))
{
    // Code here will be executed when isalpha(argv[1][j]) is false.
}