我在使用 memset 时收到“类型参数”警告
I'm having an `argument of type` warning while using memset
我有数组;
volatile uint32_t SoftTimers[8] ;
我想在程序中将数组的所有内容重置为零(不是初始化)。我搜索了这个并找到了 memset
。但是我在使用这个功能时有这个警告(不是错误),这是一个问题吗?
我这样使用 memset
:
memset(SoftTimers, 0, sizeof(SoftTimers));
这是警告信息:
warning: #167-D: argument of type "volatile uint32_t *" is incompatible with parameter of type "void *"
在这种情况下您不能使用 memset,因为它需要一个非易失性指针,而您正试图传递一个易失性指针:
6.7.3 Type qualifiers
- If an attempt is
made to refer to an object defined with a volatile-qualified type through use of an lvalue
with non-volatile-qualified type, the behavior is undefined.
编写您自己的函数,它接受一个指向 volatile uint32_t
类型的指针。
我有数组;
volatile uint32_t SoftTimers[8] ;
我想在程序中将数组的所有内容重置为零(不是初始化)。我搜索了这个并找到了 memset
。但是我在使用这个功能时有这个警告(不是错误),这是一个问题吗?
我这样使用 memset
:
memset(SoftTimers, 0, sizeof(SoftTimers));
这是警告信息:
warning: #167-D: argument of type "volatile uint32_t *" is incompatible with parameter of type "void *"
在这种情况下您不能使用 memset,因为它需要一个非易失性指针,而您正试图传递一个易失性指针:
6.7.3 Type qualifiers
- If an attempt is made to refer to an object defined with a volatile-qualified type through use of an lvalue with non-volatile-qualified type, the behavior is undefined.
编写您自己的函数,它接受一个指向 volatile uint32_t
类型的指针。