This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: C99
- From: Doug Evans <dje at google dot com>
- To: Mark Kettenis <mark dot kettenis at xs4all dot nl>
- Cc: Tom Tromey <tromey at redhat dot com>, gdb <gdb at sourceware dot org>
- Date: Wed, 17 Jul 2013 14:12:47 -0700
- 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> <201307172048 dot r6HKmZhD018958 at glazunov dot sibelius dot xs4all dot nl>
On Wed, Jul 17, 2013 at 1:48 PM, Mark Kettenis <mark.kettenis@xs4all.nl> wrote:
>> > 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;
> }
Yeah, except I'm not seeing why it's a problem. Why is it a bad
decision? What class of bugs does it cause?
I can see that it makes it easier to find all the locals, but I'm more
for declaring/initializing them close to their use.