This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: C99
- From: Mark Kettenis <mark dot kettenis at xs4all dot nl>
- To: dje at google dot com
- Cc: tromey at redhat dot com, gdb at sourceware dot org
- Date: Wed, 17 Jul 2013 22:48:35 +0200 (CEST)
- Subject: Re: C99
- References: <87wqoqi5yf dot fsf at fleche dot redhat dot com> <201307162122 dot r6GLMlMx012078 at glazunov dot sibelius dot xs4all dot nl> <CADPb22QkGUQ8v_PZBKW23xE71xwtv3NNhEkb5Kwy13+E5GRjAQ at mail dot gmail dot com>
> Date: Tue, 16 Jul 2013 14:40:24 -0700
> From: Doug Evans <dje@google.com>
>
> On Tue, Jul 16, 2013 at 2:22 PM, Mark Kettenis <mark.kettenis@xs4all.nl> wrote:
> >> From: Tom Tromey <tromey@redhat.com>
> >> Date: Tue, 16 Jul 2013 14:51:36 -0600
> >>
> >> I'd like to draw attention to this patch:
> >>
> >> http://sourceware.org/ml/gdb-patches/2013-06/msg00808.html
> >>
> >> This points out that gdb has been unconditionally using a GCC extension,
> >> apparently since at least 2010; the patch introducing the varargs define
> >> in tracepoint.c was 7c56ce7 (2010-04-09).
> >>
> >> The patch proposes replacing this with the corresponding C99 construct.
> >>
> >> So, I'd like to propose we allow the use of C99 in gdb. In particular I
> >> think we ought to require a C99 preprocessor -- enabling this particular
> >> patch to go in and also allowing the use of "//" comments.
> >
> > Perhaps it is time to move on and start requiring a C99 compiler for GDB.
> > But "//" comments are offensive to real C programmers! ;)
> >
> > Seriously though. This points out that such a switch has some
> > consequences for our coding standards. We have a fairly consistent
> > coding style in GDB, which makes it easy for people to move around in
> > the codebase without getting distracted by the "looks" of the code. I
> > think it's worth some effort to keep it that way. And allowing "//"
> > comments isn't going to help. I'd vote for not using them at all.
>
> I don't see // as a serious issue, but I can live with it either way.
>
> > However, a more important C99 "misfeature" that affects the coding
> > standard is the possibility to declare varaibles anywhere in the code.
> > We should not allow this, except for declaring loop variables in a
> > for() statement.
>
> Can you elaborate?
Code like this:
int
foobar(char *foo, int bar)
{
sprintf(foo, "%d", bar)
int j = strlen(foo);
return j;
}
is bad if you're trained to look for variable declerations at the
start of a block. C90 doesn't allow this; C99 changed that. Most
hardcore C programmers consider this a bad decision by the standard
committe. Most people do accept the following though:
int
foobar(int bar)
{
int sum = 0;
for (int i = 0; i < bar; i++)
sum += i;
return sum;
}