[Cbe-oss-dev] [PATCH 4/6] spufs: extension of spu_create to support affinity definition

Segher Boessenkool segher at kernel.crashing.org
Wed Feb 14 07:54:27 EST 2007


>>> style: don't initialize local variables in their definition.
>>
>> Why ? I do that all the time
>
> gcc won't be able to warn about uninitialized use if you do it.

Well of course not; because it _is_ initialised!

> If you have
>
> int foo(void)
> {
> 	int bar = 0;
> 	int ret;
>
> 	ret = something();
> 	/*
> 	 * lots of code here ...
> 	 */
> 	if (!ret)
> 		bar = get_bar();
>
> 	return bar;
> }
>
> it can easily happen that you add a user of bar before the
> initialization, therefore better write it as
>
> int foo(void)
> {
> 	int bar;
> 	int ret;
>
> 	ret = something();
> 	/*
> 	 * lots of code here ...
> 	 */
> 	bar = 0;
> 	if (!ret)
> 		bar = get_bar();
>
> 	return bar;
> }
>
> or
>
> int foo(void)
> {
> 	int bar;
> 	int ret;
>
> 	ret = something();
> 	/*
> 	 * lots of code here ...
> 	 */
> 	if (!ret)
> 		bar = get_bar();
> 	else
> 		bar = 0;
>
> 	return bar;
> }

Or write your code as short, obvious functions (like
you're supposed to do anyway), and none of this could
ever be a problem ;-)

I do agree that as a point of style, it's better to
initialise variables explicitly at a point that makes
sense for the overall program flow; but that's all it
is, style.


Segher




More information about the cbe-oss-dev mailing list