std C/C++ patch #9

David Scott Page page at cs.utexas.edu
Mon Apr 29 16:40:56 EDT 2002


Eddie,

SPARCs are not *that* picky. They just require accesses to be on natural 
alignments for the particular type (else bus-error):

char	1 byte boundary  (ldb,stb)
short	2		 (ldh,sth)
int	4		 (ld,st)
long	4 ILP32 (8 LP64) (ld,st(ldd,std))
double  8		 (ldd,std)
...

Hence, on Solaris/SPARC,

struct click_ether {
    uint8_t	ether_dhost[6];
    uint8_t	ether_shost[6];
    uint16_t	ether_type;
}/* __attribute__ ((packed));*/

requires two byte alignment; and sizeof(click_ether) == 14.  

Thanks for the reference from the standard - sizeof() seems a bit less
arbitrary, now.

--
Scott Page


> 
> Hi Scott,
> 
> > Considering the above, and that KCC, Sun CC, and g++ on Solaris all
> > generate #pragma-free code satisfying your sizeof criteria (category
> > 1, below) for ether, ip, etc.,
> 
> Really?!?
> 
> This would imply that
> 
>      click_ether e[2];
>      assert(((uint8_t *)(e + 1)) != ((uint8_t *)e + sizeof(click_ether)));
> 
> which would really weird me out. (Presumably the click_ether structures are
> laid out with 2 bytes of padding, so ((uint8_t*)(e + 1) - (uint8_t*)e) == 16.
> But you're saying that sizeof(click_ether) == 14.)
> 
> Eddie
> 




More information about the click mailing list