Re: [patch 2/2] kernel/power/disk.c string fix and if-less iterator

From: Horst von Brand
Date: Tue Jun 21 2005 - 10:26:11 EST


Pavel Machek <pavel@xxxxxxx> wrote:
> domen@xxxxxxxxxxxx said:
> > The attached patch:

> > o Fixes kernel/power/disk.c string declared as 'char *p = "...";' to be
> > declared as 'char p[] = "...";', as pointed by Jeff Garzik.
>
> ? Why was char *p ... wrong? Because you could not do sizeof() later?

Note also that this increases the stack usage of the function and slows it
down, as this means allocating an array and filling it in at call time.

>
> > o Replaces:
> > i++:
> > if (i > 3) i = 0;
> >
> > By:
> > i = (i + 1) % (sizeof(p) - 1);
> >
> > Which is if-less, and the adjust value is evaluated by the compiler in
> > compile-time in case the string related to this loop is modified.
>
> Well, why not...

Because for that it could be done with a #define of the string... and it is
not that this could change any time soon, so IMHO a constant 3 + comment
would be fine.
--
Dr. Horst H. von Brand User #22616 counter.li.org
Departamento de Informatica Fono: +56 32 654431
Universidad Tecnica Federico Santa Maria +56 32 654239
Casilla 110-V, Valparaiso, Chile Fax: +56 32 797513
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/