Re: sparse segfaults
From: Linus Torvalds
Date: Sun Nov 21 2004 - 17:38:48 EST
On Sun, 21 Nov 2004, linux-os wrote:
> >
> > int tickadj = 500/HZ ? : 1; /* microsecs */
> >
> > which makes it look like sparse doesn't understand such constructions.
>
> I don't think any 'C' compiler should understand such constructions
> either.
> There is no result for the TRUE condition, and the standard
> does not provide for a default. The compiler should have written
> a diagnostic.
Actually, this is documented gcc behaviour, where a missing true condition
is substituted with the condition value.
So what the above does is set "tickadj" to 500/HZ _except_ if that
underflows to zero, in which case tickadj gets the value 1.
IOW, it's the same as
int tickadj = 500/HZ ? 500/HZ : 1;
except that the short syntax is not only shorter, but it's extremely
convenient in macros etc, because it only evaluates the value once, ie you
can do
int tickadj = *ptr++ ? : 1;
and it's well-behaved in that it increments the pointer only once.
Linus
-
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/