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 17:10:08 +0200

I've only got version 3.3 installed at the moment, but I got the same
generated assembly for the two "copy" functions below with -O or above
(without -O, avrgcc produces such large and unintelligble code that it's
hardly worth bothering about).  My preferred version, using an extra local
variable, also produces exactly the same code - using an extra variable here
has no overhead, and removes all warnings from the compiler, and avoids ugly
typecasts in the code.

void copy3(unsigned char *dst, void *src)
{
 unsigned char* p = src;
 while (*p) {
  *dst++ = *p++;
 }
}

mvh.,

David





----- Original Message -----
From: "Dave Hylands" <address@hidden>
To: "David Gay" <address@hidden>; "Harald Kipp"
<address@hidden>
Cc: <address@hidden>
Sent: Thursday, August 05, 2004 3:38 PM
Subject: RE: [avr-gcc-list] Deprecated warning on 3.4.1


The

*dst++ = *src++

Is fairly traditional code used inside a copy loop. So I think that the
original intent was this:

*dst++ = *src;
src++;

So the original binding was correct.

I think that this needs to be rewritten as:

*dst = *(unsigned char *)src;
src = (whatever type src is)((unsigned char *)src + 1);

The original form was equivalent to:

(unsigned char *)src = (unsigned char *)src + 1;

Compiling this snippet (with -O)

  void copy( unsigned char *dst, void *src )
  {
     while ( *(unsigned char *)src )
     {
        *dst++ = *(((unsigned char *)src)++);
     }
  }

Produces identical assembly output (minus the warning) to this version
(also using -O):

  void copy( unsigned char *dst, void *src )
  {
     while ( *(unsigned char *)src )
     {
        *dst++ = *(unsigned char *)src;
        src = (unsigned char *)src + 1;
     }
  }

So we can be sure that they are in fact equivalent.

--
Dave Hylands
Vancouver, BC, Canada
http://www.DaveHylands.com/

> ++ binds tighter than *, so you've done:
>
>    dereference the incremented cast of src to unsigned char *
>
> (and so you are indeed using the result of a cast as an lvalue)
>
> You presumably wanted
>
>    (*((unsigned char *)src))++
>
> which is
>
>    increment the dereference of the cast of src to unsigned char *
>
> David Gay
>
> _______________________________________________
> avr-gcc-list mailing list
> address@hidden
> http://www.avr1.org/mailman/listinfo/avr-gcc-list
>
>


_______________________________________________
avr-gcc-list mailing list
address@hidden
http://www.avr1.org/mailman/listinfo/avr-gcc-list





reply via email to

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