我发现了这个错误(将'const uint8_t(*)[kStreamChunkSize]'发送到'void *'类型的参数会丢弃限定符)? [英] I found this error (Sending 'const uint8_t (*)[kStreamChunkSize]' to parameter of type 'void *' discards qualifiers)?
问题描述
我在NSData文件中有一种方法.
I have one method in NSData file.
- (void)getBytes:(void *)buffer;
但是当我使用这种方法时..
But when i used this method like..
const uint8_t bytes [kStreamChunkSize];
[chunk getBytes:&bytes];
然后给出此错误
向'void *'类型的参数发送'const uint8_t(*)[kStreamChunkSize]'会丢弃限定符
Sending 'const uint8_t (*)[kStreamChunkSize]' to parameter of type 'void *' discards qualifiers
如何解决此错误.请帮助我.
How to solve this error. Please help me.
推荐答案
它丢弃了const
限定符,这是一个问题. getBytes:
通过将字节写入传递的数组中来获取字节.但是,您不能写入const
字节的数组(这样做会调用未定义的行为),这就是const
的含义.将数组的声明更改为
It discards the const
qualifier and that's a problem. getBytes:
gets the bytes by writing them into the array passed in. However, you can't write in an array of const
bytes (doing so invokes undefined behavior), that's what const
means. Change the declaration of your array to
uint8_t bytes[kStreamChunkSize];
此外,不要将指针传递给数组-如果仅使用不带&
运算符的名称,则数组将衰减为指向其第一个元素的指针.
Furthermore, don't pass a pointer to the array - if you simply use its name without the &
operator, it will decay into a pointer to its first element anyway.
这篇关于我发现了这个错误(将'const uint8_t(*)[kStreamChunkSize]'发送到'void *'类型的参数会丢弃限定符)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!