C++ – 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];

bufferPattern is : const patternp * bufferPattern;

patternp is a typedef of the type : typedef prog_uchar patternp[NUM_ROWS];

I can see in the Reference that prog_uchar is 1 byte ( 0 to 255 ). So I do not understand the error about losing precision? Any idea?

Best Solution

The problem is in this sub expression


The variable bufferPattern is of type const patternp * so when the indexer is applied the result is patternp. The type "patternp" is typedef to prog_uchar[]. So in actuality this expression is saying

Cast a prog_uchar* to a byte

Byte is almost certainly a single byte value and prog_uchar* is the platform specific pointer type (either 4 or 8 bytes). This does indeed result in a loss of precision. Perhaps you meant to dereferenc this value?