staging: dgap: Question about declaring variables
Mark Hounschell
markh at compro.net
Thu May 22 20:59:00 UTC 2014
On 05/22/2014 04:38 PM, Dan Carpenter wrote:
> On Thu, May 22, 2014 at 01:49:22PM -0400, Mark Hounschell wrote:
>> I understand that unnecessarily initializing them is wrong. But if they
>> do need initialized, is it preferred to do it in the declaration or in
>> the code before it is used?
>
> Which ever is more clear. It's up to you. Or do you mean code like
> this?
>
> 1)
> ret = -ENOMEM;
> p = kmalloc();
> if (!p)
> goto err_free_x;
>
> 2)
> p = kmalloc();
> if (!p) {
> ret = -ENOMEM;
> goto err_free_x;
> }
>
> That's also up to the maintainer. People debate which one is cleaner.
> I normally do the second one, unless the rest of the file does the first
> one. The first one apparently is slightly better assembly on current
> GCCs.
>
Actually something a little more basic. I'm removing "unnecessary"
initialization of variables in declarations. I guess they are all pretty
much "unnecessary"??
Should I change something like this:
int function(somevar)
{
int count = 0;
for (something) {
count++;
}
return count;
}
to something like this?
int function(somevar)
{
int count;
count = 0;
for (something) {
count++;
}
return count;
}
Thanks
Mark
More information about the devel
mailing list