avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Deprecated warning on 3.4.1


From: David Brown
Subject: Re: [avr-gcc-list] Deprecated warning on 3.4.1
Date: Thu, 5 Aug 2004 09:05:00 +0200

Such casts should certainly issue a warning, as they could easily lead to
problems, at least on other processors.  Suppose you are using a processor
which requires 16-bit data to be aligned properly, and src is a pointer to
such data (unsigned short*).  Then the ((unsigned char *) src)++ expresion
leaves "src" with a value that is illegal for its type - not a good thing to
do.  In general, the effect to arithmetic (like ++) on a variable is
dependand on its exact type, so messing with that type is a bad plan.

I would say that a better way to write such code would be to introduce a new
local variable of type (unsigned char*), initialised to src.  You can then
use the new pointer freely.



> The ++ operator makes ((unsigned char *) src) an lvalue.

> Think about ++ as being equivalent to += 1 and it will probably make
> more sense.

> Hmm. I wonder what the "new" way of doing things is? (since this appears
> to be deprectaed).

>> At
>>
>>    *dst++ = *((unsigned char *) src)++;
>>
>> the compiler 3.4.1 (WinAVR) mumbles
>>
>>    warning: use of cast expressions as lvalues is deprecated
>>





reply via email to

[Prev in Thread] Current Thread [Next in Thread]