tags:

views:

777

answers:

3

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?

+3  A: 

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.

Cătălin Pitiș
Thanks, cannot accept because you are right about the reason but Jared got the reason and the solution.
Daok
+5  A: 

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. 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?

(byte)(*(bufferPattern[iRow]))
JaredPar
You got the problem and the right solution. Thx, my C is a little rusty, I need to wake up! Thx
Daok
@Daok, drink more coffee ;)
JaredPar
Incidentally, as the platform is AVR - pointers are only 16bits.
Peter Gibson
A: 

bufferPattern[ iRow ] resolves to a patternp, which is a 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!

xtofl