Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 6 Apr 2003 23:05:22 +0200
From:      Maxime Henrion <mux@freebsd.org>
To:        Bruce Evans <bde@zeta.org.au>
Cc:        cvs-all@FreeBSD.org
Subject:   Re: cvs commit: src/sys/dev/fxp if_fxpreg.h
Message-ID:  <20030406210522.GA1750@elvis.mu.org>
In-Reply-To: <20030406134416.A3578@gamplex.bde.org>
References:  <200304052346.h35Nkwoi037742@repoman.freebsd.org> <20030406134416.A3578@gamplex.bde.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Bruce Evans wrote:
> On Sat, 5 Apr 2003, Maxime Henrion wrote:
> 
> > mux         2003/04/05 15:46:58 PST
> >
> >   FreeBSD src repository
> >
> >   Modified files:
> >     sys/dev/fxp          if_fxpreg.h
> >   Log:
> >   ...
> >   - Change some u_int to u_int8_t which make more sense here since
> >     we're really defining bytes.  That produces the same code due to
> >     how bitfields work.
> 
> This gives undefined behaviour and thus produces random code if it is
> compiled by a C compiler (unless Bool_t happens to be u_int8_t).  From
> n869.txt:
> 
>        [#8]  A  bit-field  shall have a type that is a qualified or
>        unqualified version of _Bool, signed int, or  unsigned  int.
> 
> I fixed this bug in many places, including in rev.1.13 of if_fxpreg.h.
> but it keeps getting reintroduced :-(.

I didn't know you fixed this before, sorry for having reverted your
previous fixes.

> Bit-fields of other integer types are an unportable gcc extension.
> They affect the struct layout in unportable apparently-undocumented
> ways.  IIRC, they don't affect internal padding but they do affect the
> size and alignment the struct -- a struct that has only uint8_t
> bit-fields in it has only the size and alignment requirements of
> uint8_t, while a struct with only u_int bit-fields in it has the size
> and alignment requirements of u_int.  This may be controlled to some
> extent using other unportable gcc extensions.

I somehow thought that C99 wasn't only allowing the use of other integer
types, but also defined the behaviour when using them, but I see that I
was wrong.  Even though I find it a pity that we can't use uint8_t in a
portable way - because we're really talking bytes there - I'll backout
this part of my changes.

Thanks for pointing this out,
Maxime



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030406210522.GA1750>