This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Network programming for eCos under linux


On Wed, Aug 08, 2001 at 03:51:17PM +0200, Andrew Lunn wrote:

> > I'm not sure this is a compiler bug - I would suspect the linux
> > compiler can't access non-aligned memory either, but at a guess
> > the kernel catches the exception and emulates it for you. If
> > that is the case, it's best avoided as performance would suck.
> 
> I don't remeber the exact details. The code was something like...
> 
> static int 
> func(char * msg, char * name ; short rr_type) {
> 
>  char *ptr;
>  int len;
>         
>  strcpy(msg,name);
>  ptr = msg + strlen(name);
> 
>  *ptr++ = ((char *)&rr_type)[0];
>  *ptr++ = ((char *)&rr_type)[1];
>  
>  len = ptr - msg;
> 
>  return len;
> }

AFAICT, that should work on an ARM.  If it doesn't, it is a
compiler bug.

> Maybe i don't have the casts correct.

There are other casts that are not going to work on ARM
architecture (accessing words on non-word boundaries, for
example).  That's not a compiler error, it's just another way
to shoot yourself in the foot with C.

> Anyway, i found the ptr was not being incremented when ptr was
> not word aligned before the first *ptr++ operation. This could
> happen because name can be any length. It worked fine on i386,
> but not on arm-elf. To me, this is a compile bug. I got around
> it by using shifts and ands instead of casts and array access.

Did you report the bug to the gcc guys?  If it really is a bug,
they'd love to hear about it.

-- 
Grant Edwards
grante@visi.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]