From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matthew Wilcox Subject: Re: [PATCH] drm/fourcc: Add DOC: overview comment Date: Thu, 23 Aug 2018 07:34:45 -0700 Message-ID: <20180823143445.GA26109@bombadil.infradead.org> References: <20180821161611.10424-1-brian.starkey@arm.com> <20180821162639.GA21697@bombadil.infradead.org> <20180821164416.GA11553@e107564-lin.cambridge.arm.com> <20180822145924.GA13763@intel.com> <20180822155732.GA39066@e107564-lin.cambridge.arm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Content-Disposition: inline In-Reply-To: <20180822155732.GA39066@e107564-lin.cambridge.arm.com> Sender: linux-kernel-owner@vger.kernel.org To: Brian Starkey Cc: Daniel Vetter , Eric Engestrom , Alexandru-Cosmin Gheorghe , Jonathan Corbet , Dave Airlie , Linux Doc Mailing List , Linux Kernel Mailing List , dri-devel , Sean Paul , Liviu Dudau , Ayan Kumar Halder List-Id: dri-devel@lists.freedesktop.org On Wed, Aug 22, 2018 at 04:57:33PM +0100, Brian Starkey wrote: > On Wed, Aug 22, 2018 at 05:11:55PM +0200, Daniel Vetter wrote: > > On Wed, Aug 22, 2018 at 4:59 PM, Eric Engestrom > > wrote: > > > On Tuesday, 2018-08-21 17:44:17 +0100, Brian Starkey wrote: > > > > On Tue, Aug 21, 2018 at 09:26:39AM -0700, Matthew Wilcox wrote: > > > > > Can you turn them into enums? This seems to work ok: > > I'm not sure that swapping out explicit 32-bit unsigned integers for > enums (unspecified width, signed integers) is necessarily a good idea, > it seems like Bad Things could happen. > > The C spec says: > > "the value of an enumeration constant shall be an integer constant > expression that has a value representable as an int" > > Which likely gives us 4 bytes to play with on all machines > that run Linux, but if drm_fourcc.h is ever going to be some kind of > standard reference, making it non-portable seems like a fail. > > And even if you do have 4 bytes in an enum, signed integers act > differently from unsigned ones, and compilers do love to invoke the UB > clause... I think you're exaggerating how much latitude C compilers have here. Further down in 6.7.2.2, it says: Each enumerated type shall be compatible with char, a signed integer type, or an unsigned integer type. The choice of type is implementation-defined, but shall be capable of representing the values of all the members of the enumeration. So if we include an integer which isn't representable in a plain int, then the compiler _must_ choose a larger type. It could choose a signed-64-bit type rather than an unsigned-32-bit type, but I can't imagine any compiler being quite so insane.