使用arm none eabi gcc的isprint()的奇怪错误消息

使用arm none eabi gcc的isprint()的奇怪错误消息,gcc,arm,avr-gcc,Gcc,Arm,Avr Gcc,我有以下代码: #include <ctype.h> void myfn(void) { uint8_t any0 = 'c'; char any1 = 'c'; if (isprint(any0)) { return; } if (isprint(any1)) { return; } } 如果我将unit8\t传递给isprint,编译器会高兴,但如果我传递char,编译器不会高兴

我有以下代码:

#include <ctype.h>

void myfn(void)
{
    uint8_t any0 = 'c';
    char any1 = 'c';

    if (isprint(any0))
    {
        return;
    }
    if (isprint(any1))
    {
        return;
    }
}
如果我将
unit8\t
传递给
isprint
,编译器会高兴,但如果我传递
char
,编译器不会高兴

isprint
的原型是:

int isprint(int c);
它需要一个
int
作为参数,我给它一个
char
。 我希望它会抱怨参数的类型,但不会抱怨与“数组下标”无关的东西

如果我将调用更改为:

if (isprint((uint8_t)any1))
有什么是我忽略的吗

我使用的编译器是:

GNU C (15:4.9.3+svn231177-1) version 4.9.3 20150529 (prerelease) (arm-none-eabi)
compiled by GNU C version 5.2.1 20151129, GMP version 6.1.0, MPFR version 3.1.3, MPC version 1.0.3
warning: MPFR header version 3.1.3 differs from library version 3.1.4.
命令行选项:

'-v' '-fshort-enums' '-specs=nosys.specs' '-specs=nano.specs'
'-mfloat-abi=soft' '-save-temps' '-Werror' '-Wpedantic' '-pedantic-errors' '-mthumb' '-fno-builtin' '-mcpu=cortex-m0' '-Wall' '-std=gnu99' '-ffunction-sections'
'-fdata-sections' '-fomit-frame-pointer' '-mabi=aapcs' '-fno-unroll-loops' '-ffast-math' '-ftree-vectorize' '-Og' '-g'

如果我使用gcc编译器为AVR
/usr/bin/AVR gcc
编译相同的代码(使用类似的命令行选项,并且我故意添加了选项
-Werror=char subscripts
),它不会抱怨
isprint
。因此,它似乎与ARM编译器有关。

事实证明,ARM的
isprint
实现是一个宏,更重要的是,头文件ctype.h包含以下注释:

对于AVR,头文件ctype.h包含:

extern int isprint(int __c) __ATTR_CONST__;

这解释了为AVR或ARM编译时的行为差异。

可能是版本差异,而不是特定于ARM或AVR。您的avr gcc是什么版本?不管怎样,这只是一个保姆的警告。你的代码很好。相关:您得到
数组下标
错误而不是函数调用参数的原因可能是
isprint
是您实现中的一个宏。@CarlNorum是的,您是对的。
isprint
的实现是一个宏,更重要的是,头文件ctype.h包含以下注释:
如果用户错误地传递了“char”而不是包含“unsigned char”的int,则这些宏的编写方式会触发gcc-Wall警告。
@CarlNorum My avr compiler是版本4.9.2,头文件ctype.h包含:
extern int isprint(int\uu c)\uu ATTR\u CONST\uuu;
。这解释了AVR和ARM之间的区别。
These macros are intentionally written in a manner that will trigger
a gcc -Wall warning if the user mistakenly passes a 'char' instead of
an int containing an 'unsigned char'.
extern int isprint(int __c) __ATTR_CONST__;