This is the mail archive of the ecos-discuss@sourceware.org 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]
Other format: [Raw text]

CGY_SWAP16() seems broken to me.



unsigned u = CYG_SWAP16(0x1234);

What would a reasonable person (who hasn't looked at
hal_endian.h) expect u to be?

I certainly expected it to be 0x3412. 

But it's not.  It's 0x123412.  

IMO, that's just plain broken.


Here's the definition from hal_endian.h:

# define CYG_SWAP16(_x_)                                        \
    ({ cyg_uint16 _x = (_x_); ((_x << 8) | (_x >> 8)); })

Why isn't it this?

# define CYG_SWAP16(_x_)                                        \
    ({ cyg_uint16 _x = (_x_); (cyg_uint16)((_x << 8) | (_x >> 8)); })

Why would anybody expect a macro named CYG_SWAP16() to return a
"24-bit value" when passed a "16-bit value"?

-- 
Grant Edwards                   grante             Yow!  Ha ha  Ha ha Ha ha
                                  at               Ha Ha Ha Ha -- When will I
                               visi.com            EVER stop HAVING FUN?!!


-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss


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