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: Harald Kipp
Subject: Re: [avr-gcc-list] Deprecated warning on 3.4.1
Date: Thu, 05 Aug 2004 12:20:02 +0200

At 09:05 05.08.2004 +0200, David Brown wrote:
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 fully understand this, but...



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.

In some cases this may introduce additional code, which
can break the application. Remember, we are not talking about
PCs, but embedded systems, where portability is not always
the main focus. Instead developers often count the number of
machine cycles. Thus, it's not "OK, let's use another local
variable for free." In my case it is bootloader code, where
every byte counts and portability is absolutely no issue.

Nevertheless I understood now, that this compiler warning
makes sense.

Thanks,

Harald




reply via email to

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