Re: C99
Doug Evans <[email protected]>
| Newsgroups | gmane.comp.gdb.devel |
|---|---|
| Message-ID | <CADPb22T_1an4N4iu7M7z2Oh_NXtig5Ut73FL7k7sjZO-GK756w@mail.gmail.com> |
On Wed, Jul 17, 2013 at 1:48 PM, Mark Kettenis <[email protected]> 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.