[Ffmpeg-devel] [PATCH] from DivX, Part 7: MSVC fixes
Dave Dodge
dododge
Thu Dec 22 20:35:45 CET 2005
On Thu, Dec 22, 2005 at 01:17:52PM -0500, Rich Felker wrote:
> On Thu, Dec 22, 2005 at 07:05:17AM -0500, Dave Dodge wrote:
> > -Wdeclaration-after-statement
> >
> > Just tried it in gcc 3.4.2 and it seems to do what you want even when
> > -std=c99 is enabled.
>
> Yes they finally added this after realizing that it's bad style,
I do find mixed declarations useful in my own projects. The main
reason is that I really like marking things const. C doesn't have a
way for me to say "make this const after the first assignment", so the
only way I can get const behavior is to define the variable with an
initializer. The initializer may require that some preconditions have
been checked, or that some complex logic has already been run. A
typical function might look something like this:
int foo(int const arg1, int const arg2)
{
/* make sure arguments are sane */
if(something is bad)
return an error
/* compute some useful values */
int const x = ...
int const y = ...
int const z = ...
/* do some work */
int const a1 = bar(x,y,z);
if(a1 == -1)
return an error
int const a2 = blah(x,a1);
if(a2 == -1)
return an error
...
}
Of course I'd use more meaningful names than x, y, and z, since these
are really named values or subexpressions rather than true variables.
Most of my functions are much less than one screen long, so finding
where an identifier is defined in a function doesn't require a lot of
hunting.
-Dave Dodge
More information about the ffmpeg-devel
mailing list