This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: C99


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]