[英]error: cast from 'const prog_uchar*' to 'byte' loses precision?
The error is at this line : 错误在这一行:
dataArray[iLedMatrix][iRow] |= (byte)(bufferPattern[iRow]) & (1<<7);
dataArray is : byte dataArray[NUMBER_LED_MATRIX][NUMBER_ROW_PER_MATRIX]; dataArray为:字节dataArray [NUMBER_LED_MATRIX] [NUMBER_ROW_PER_MATRIX];
bufferPattern is : const patternp * bufferPattern; bufferPattern是:const patternp * bufferPattern;
patternp is a typedef of the type : typedef prog_uchar patternp[NUM_ROWS]; patternp是类型的typedef:typedef prog_uchar patternp [NUM_ROWS];
I can see in the Reference that prog_uchar is 1 byte ( 0 to 255 ). 我可以在参考文献中看到prog_uchar是1个字节(0到255)。 So I do not understand the error about losing precision?
所以我不明白关于失去精度的错误吗? Any idea?
任何想法?
The problem is in this sub expression 问题出在这个子表达式中
(byte)(bufferPattern[iRow])
The variable bufferPattern is of type const patternp *
so when the indexer is applied the result is patternp. 变量bufferPattern的类型为
const patternp *
因此应用索引器时,结果为patternp。 The type "patternp" is typedef to prog_uchar[]. 类型“ patternp”是prog_uchar []的typedef。 So in actuality this expression is saying
所以实际上这个表达是说
Cast a prog_uchar* to a byte
将prog_uchar *强制转换为一个字节
Byte is almost certainly a single byte value and prog_uchar* is the platform specific pointer type (either 4 or 8 bytes). 字节几乎可以肯定是一个字节值,而prog_uchar *是平台特定的指针类型(4或8字节)。 This does indeed result in a loss of precision.
实际上确实导致精度损失。 Perhaps you meant to dereferenc this value?
也许您打算取消引用此值?
(byte)(*(bufferPattern[iRow]))
You are trying to cast from a pointer type to byte. 您试图将指针类型转换为字节。 A pointer type is usually represented on 4 bytes (32 bit OS) or 8 bytes (64 bits), and you are trying to convert its address value to 1 byte.
指针类型通常用4个字节(32位OS)或8个字节(64位)表示,并且您试图将其地址值转换为1个字节。
bufferPattern[ iRow ]
resolves to a patternp
, which is a prog_uchar[ NUM_ROWS ]
. bufferPattern[ iRow ]
解析为patternp
,它是prog_uchar[ NUM_ROWS ]
。
So you're actually casting an array (implemented as a pointer) to a byte. 因此,您实际上是将数组(实现为指针)转换为字节。 Makes no sense;
没有意义; lucky the compiler warned you!
幸运的是编译器警告您!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.