> > > So everybody who does not want to know how integers are
> > > represented on the current architecture writes
> > > start = p[0] + (p[1] << 8) + (p[2] << 16) + (p[3] << 24);
> > > And it just works.
> >
> > Really, ...
>
> I have been arguing that casts are bad ...

Thanks for the hint.  Something slippery here.

How best to say copy bytes matters much for tools such as the sg utils
that work at the level of cdb/ data/ status/ sense.

I imagine ([EMAIL PROTECTED],
[EMAIL PROTECTED]) isn't the place to resolve this,
so instead I've posted into comp.arch.embedded as quoted below.

Pat LaVarre

--- 

Newsgroups: comp.arch.embedded
Subject: whose cc recognises byte moves
Message-ID: <[EMAIL PROTECTED]>

> > > > Newsgroups:comp.arch.embedded
> > > > ...
> > > > using the usual compilers for 8-bit
> > > > embedded chips has been a let down
> > > ...
> > > Do you have any concrete examples?
> > > ...

Lately elsewhere I saw people mocking the practice of writing explicit
byte assignments in C, which brings me here now asking, anyone with an
8051 compiler want to try compiling the following code snippet?
Possibly before I saw:

1) Some compilers actually involve 32-bit arithmetic, rather than
moving bytes, ouch.

2) Some compilers allocate the unsigned long twice, once as a local
variable, then again as a separate result, ouch.

3) Many compilers fail to produce the same machine code for both of
these expressions of the same idea e.g. my 32-bit Linux desktop `gcc
--version` 3.2.2 here now, when run as c.a.e. lately helpfully
suggested:

gcc -c -fomit-frame-pointer -O3 -Wall -W hi.c
objdump -dS hi.o

A frustrating failure of the C compilers for 8 and 16 bit
microcontrollers to understand what I meant by what I said plainly and
simply in the first place, yes?

Pat LaVarre

/// ways of fetching a potentially misaligned big-endian 32-bits ...
/// (op x25 Read Capacity bytes[4:5:6:7] is disc bytes per read block)

long sub1(char * chars)
{
        long result;
        result = (chars[4] << 0x18) |
                (chars[5] << 0x10) |
                (chars[6] << 0x08) |
                (chars[7] << 0x00);
        return result;
}

#include <endian.h>

#if __BYTE_ORDER != __BIG_ENDIAN /* if byte 0 lsb */
#define LIL(I, N) (((unsigned char *)&(I))[N])
#define BIG(I, N) LIL(I, sizeof (I) - (N))

#else /* else if byte 0 msb */
#define BIG(I, N) (((unsigned char *)&(I))[N])
#define LIL(I, N) BIG(I, sizeof (I) - (N))
#endif

long sub2(char * chars)
{
        long result;
        LIL(result, 3) = chars[4];
        LIL(result, 2) = chars[5];
        LIL(result, 1) = chars[6];
        LIL(result, 0) = chars[7];
        return result;
}




-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to