From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-Version: 1.0 In-Reply-To: <0ed0a6d52f2a1c49363d9b032c8f178a@kw.quanstro.net> References: <19f6168fb6b109424ddbb1d276d62e6b@brasstown.quanstro.net> <0ed0a6d52f2a1c49363d9b032c8f178a@kw.quanstro.net> Date: Sun, 1 Jul 2012 20:24:58 -0400 Message-ID: From: Comeau At9Fans To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Content-Type: multipart/alternative; boundary=14dae9399cadef691e04c3cdd325 Subject: Re: [9fans] cc nit? Topicbox-Message-UUID: a0e7b50a-ead7-11e9-9d60-3106f5b1d025 --14dae9399cadef691e04c3cdd325 Content-Type: text/plain; charset=ISO-8859-1 On Sun, Jul 1, 2012 at 6:45 PM, erik quanstrom wrote: > > Many compilers do just that, however, that said, unless the compiler is > > prepared for it, since it effectively yields a struct of zero size which > > normally is a no-go, it could produce bugs involving sizeof, > initializers, > > pointer addition et al, even some divisions by zero if the compiler is > > making certain assumptions already, unless it already can have zero > length > > objects of this nature for some other reasons. > > actually, kenc is pretty good about all these. if you have > > struct fu {void x;}; > > and take sizeof(struct fu), that will give a diagnostic error. > > the reason i avoided it was to not mess with the grammer, but if this is a > common thing, maybe it's no big deal. > > though as charles points out, it is a bit of a waste of time. > If my memory serves, there is some wiggle room in C89 about how the empty struct works, though generally it wouldn't fly, and C99 disallows it, while C++ allows it (but it's sizeof > 0). Plus it's a common extension made prevalent via gcc. -- Greg Comeau / 4.3.10.1 with C++0xisms now in beta! Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90. Comeau C/C++ with Dinkumware's Libraries... Have you tried it? --14dae9399cadef691e04c3cdd325 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Sun, Jul 1, 2012 at 6:45 PM, erik quanstrom <quanstro@quanstro.net<= /a>> wrote:
> Many compilers do just that, however, that said, unl= ess the compiler is
> prepared for it, since it effectively yields a struct of zero size whi= ch
> normally is a no-go, it could produce bugs involving sizeof, initializ= ers,
> pointer addition et al, even some divisions by zero if the compiler is=
> making certain assumptions already, unless it already can have zero le= ngth
> objects of this nature for some other reasons.

actually, kenc is pretty good about all these. =A0if you have

=A0 =A0 =A0 =A0 struct fu {void x;};

and take sizeof(struct fu), that will give a diagnostic error.

the reason i avoided it was to not mess with the grammer, but if this is a<= br> common thing, maybe it's no big deal.

though as charles points out, it is a bit of a waste of time.
=
If my memory serves, there is some wiggle room in C89 about how t= he empty struct works, though generally it wouldn't fly, and C99 disall= ows it, while C++ allows it (but it's sizeof > 0). =A0Plus it's = a common extension made prevalent via gcc.

--
Greg Comeau / 4.3.10.1 with C++0xisms now in bet= a!
World Class Compilers: =A0Breathtaking C++, Amazing C99, Fabulous C90.=
Comeau C/C++ with Dinkumware's Libraries... Have you tried i= t?

--14dae9399cadef691e04c3cdd325--