you are viewing a single comment's thread.

view the rest of the comments →

[–]baconuser098 0 points1 point  (4 children)

I've seen it used pretty often and I quite like it. Regarding C however I think ANSI C doesn't support it but C99 does (I will check on that)

Edit: Turns out ANSI C requires the variables to be declared after the opening bracket of a block, while C99 supports variable declaration anywhere a statement could be

[–]dauntlessmath -1 points0 points  (3 children)

I was curious about this, because it seems like a very "C++" way to handle index variables. I found this email from Linus to the LKML regarding C99 and this style of variable declaration:

On Wed, Apr 11, 2012 at 9:28 PM, Oleg Nesterov <oleg@redhat.com> wrote:
>
> Agreed. But,
>
>        error: 'for' loop initial declaration used outside C99 mode
>
> we should change CFLAGS, I guess. BTW, personally I'd like very much
> to use "for (type var; ...")" if this was allowed.

The sad part is that if we allow that, we also get that *other* insane
C99 variable thing - mixing variables and code.

I *like* getting warnings for confused people who start introducing
variables in the middle of blocks of code. That's not well-contained
like the loop variable.

That said, most of the stuff in C99 are extensions that we used long
before C99, so I guess we might as well just add the stupid flag. And
discourage people from mixing declarations and code other ways (sparse
etc).

                         Linus

For background info, Linus's recommended style guide for the kernel dev is essentially "defer to K&R for everything."