[Cbe-oss-dev] [PATCH 4/6] spufs: extension of spu_create to support affinity definition
Arnd Bergmann
arnd at arndb.de
Tue Feb 13 07:36:33 EST 2007
On Monday 12 February 2007 21:07, Benjamin Herrenschmidt wrote:
>
> > > {
> > > int ret;
> > > + struct spu_gang *gang = NULL;
> > > + struct spu_context *neighbor = NULL;
> > >
> > > ret = -EPERM;
> > > if ((flags & SPU_CREATE_NOSCHED) &&
> >
> > 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.
There are exceptions, e.g. when a variable is basically the object
pointer, as in
int callback(void *data)
{
struct foo *foo = data;
...
}
I do it as well.
But especially variables initialized to NULL or 0 smell wrong.
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;
}
Arnd <><
More information about the cbe-oss-dev
mailing list