无法从函数返回 boolean 值

标签 c function boolean

这是 C 语言的代码片段:

static bool is_ascii_value_of_digit(char ascii_value){

    if((ascii_value<40)&&(ascii_value >= 30)){
        return true;
    }
    return false;
}

avr studio gcc 编译器给我错误:

../calculator.h:4: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'is_ascii_value_of_digit'

类似的错误在其他函数中也很明显。我不知道为什么会这样。花了一个小时搞清楚原因,最后放弃了。据我在网上看到的,我的语法没有问题。可能是我忽略的地方。

问题已解决!

非常感谢您的快速帮助,因为它节省了我很多时间。我假设 bool 是 c 中的关键字。

最佳答案

您可能刚刚忘记了 #include <stdbool.h> .

但是,函数的名称和行为不匹配,

if((ascii_value<40)&&(ascii_value >= 30))

十进制数字,0-9,占据ASCII表中的48-57位,即十六进制0x30 - 0x39 , 所以为了匹配名字,你应该测试

if (ascii_value < 0x3A && ascii_value >= 0x30)

关于无法从函数返回 boolean 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8751808/

相关文章:

c - 如何将标准输入读入字符串变量直到 C 中的 EOF?

python - Numpy 在行对中应用函数并累积结果

javascript - 为什么仅在第一个函数后才更改数组值?

方案 - 将 boolean 值转换为字符串?

math - boolean 代数文章/书

c - section 和 task openmp 的区别

c - 如何使用带命令行参数的嵌套 Switch?

c - LD_PRELOAD 不能拦截系统调用,只能拦截libcalls?

r - R中的错误: could not find function . ..

c - C 中的 boolean 函数