From: Brandon Williams <bmwill@google.com>
To: Jeff King <peff@peff.net>
Cc: "Junio C Hamano" <gitster@pobox.com>,
"René Scharfe" <l.s.r@web.de>,
"Andreas Schwab" <schwab@linux-m68k.org>,
"Git List" <git@vger.kernel.org>
Subject: Re: [PATCH] strbuf: use designated initializers in STRBUF_INIT
Date: Mon, 10 Jul 2017 15:41:34 -0700 [thread overview]
Message-ID: <20170710224134.GA161700@google.com> (raw)
In-Reply-To: <20170710070342.txmlwwq6gvjkwtw7@sigill.intra.peff.net>
On 07/10, Jeff King wrote:
> On Sun, Jul 09, 2017 at 10:05:49AM -0700, Junio C Hamano wrote:
>
> > René Scharfe <l.s.r@web.de> writes:
> >
> > > I wonder when we can begin to target C99 in git's source, though. :)
> >
> > Let's get the ball rolling by starting to use some of the useful
> > features like designated initializers, perhaps, in a small, critical
> > and reasonably stable part of the system that anybody must compile,
> > leave it in one full release cycle or two, and when we hear nobody
> > complains, introduce it en masse for the remainder of the system?
> >
> > That way, we will see if there are people who need pre-C99 soon
> > enough, and we won't have to scramble reverting too many changes
> > when it happens.
>
> Neat idea. Something like this?
>
> -- >8 --
> Subject: [PATCH] strbuf: use designated initializers in STRBUF_INIT
>
> There are certain C99 features that might be nice to use in
> our code base, but we've hesitated to do so in order to
> avoid breaking compatibility with older compilers. But we
> don't actually know if people are even using pre-C99
> compilers these days.
>
> One way to figure that out is to introduce a very small use
> of a feature, and see if anybody complains. The strbuf code
> is a good place to do this for a few reasons:
>
> - it always gets compiled, no matter which Makefile knobs
> have been tweaked.
>
> - it's very stable; this definition hasn't changed in a
> long time and is not likely to (so if we have to revert,
> it's unlikely to cause headaches)
>
> If this patch can survive a few releases without complaint,
> then we can feel more confident that designated initializers
> are widely supported by our user base. It also is an
> indication that other C99 features may be supported, but not
> a guarantee (e.g., gcc had designated initializers before
> C99 existed).
>
> And if we do get complaints, then we'll have gained some
> data and we can easily revert this patch.
>
> Signed-off-by: Jeff King <peff@peff.net>
> ---
> I suspected we could also do something with __STDC_VERSION__, though I
> wonder what compilers set it to when not in standards-compliant mode.
> gcc-6 claims C11 when no specific -std flag is given.
>
> And obviously before releasing this or anything similar, it would be
> nice to see results from people building pu. I'm especially curious
> whether MSVC would work with this (or if people even still use it, since
> Git for Windows is pretty mature?).
>
> strbuf.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/strbuf.h b/strbuf.h
> index 2075384e0..e705b94db 100644
> --- a/strbuf.h
> +++ b/strbuf.h
> @@ -68,7 +68,7 @@ struct strbuf {
> };
>
> extern char strbuf_slopbuf[];
> -#define STRBUF_INIT { 0, 0, strbuf_slopbuf }
> +#define STRBUF_INIT { .alloc = 0, .len = 0, .buf = strbuf_slopbuf }
I love that this is happening! And maybe someday soon we can do:
for (int i = 0; i < n; i++)
So that we can scope loop variables to the loops themselves.
--
Brandon Williams
prev parent reply other threads:[~2017-07-10 22:41 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-10 7:03 [PATCH] strbuf: use designated initializers in STRBUF_INIT Jeff King
2017-07-10 14:57 ` Ben Peart
2017-07-10 16:04 ` Jeff King
2017-07-10 17:57 ` Ben Peart
2017-07-11 5:01 ` Mike Hommey
2017-07-11 15:31 ` Junio C Hamano
2017-07-12 19:12 ` Ævar Arnfjörð Bjarmason
2017-07-12 21:08 ` Junio C Hamano
2017-07-13 22:24 ` Johannes Sixt
2017-07-10 16:44 ` Junio C Hamano
2017-07-10 17:33 ` Stefan Beller
2017-07-10 21:46 ` Junio C Hamano
2017-07-10 17:10 ` Andreas Schwab
2017-07-10 19:57 ` Johannes Sixt
2017-07-10 20:38 ` Junio C Hamano
2017-07-10 21:11 ` Johannes Sixt
2017-07-10 21:38 ` Junio C Hamano
2017-07-14 16:11 ` Junio C Hamano
2017-07-14 17:13 ` Stefan Beller
2017-07-14 17:36 ` Jeff King
2017-07-14 18:48 ` Junio C Hamano
2017-07-14 19:16 ` Junio C Hamano
2017-07-19 18:19 ` [PATCH] objects: scope count variable to loop Stefan Beller
2017-07-19 18:23 ` Brandon Williams
2017-07-24 17:08 ` Jeff King
2017-07-24 17:12 ` Stefan Beller
2017-07-24 18:05 ` Jeff King
2017-07-14 19:28 ` [PATCH] strbuf: use designated initializers in STRBUF_INIT Ævar Arnfjörð Bjarmason
2017-07-14 22:26 ` Junio C Hamano
2017-07-14 22:43 ` Mike Hommey
2017-07-15 11:08 ` Jeff King
2017-07-11 4:38 ` Jeff King
2017-07-11 0:05 ` brian m. carlson
2017-07-11 0:07 ` Stefan Beller
2017-07-11 0:10 ` brian m. carlson
2017-07-11 5:24 ` Johannes Sixt
2017-07-12 1:26 ` brian m. carlson
2017-07-12 18:25 ` Johannes Sixt
2017-07-10 22:41 ` Brandon Williams [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170710224134.GA161700@google.com \
--to=bmwill@google.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=l.s.r@web.de \
--cc=peff@peff.net \
--cc=schwab@linux-m68k.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.