Re: GCC 3.4 Heads-up

From: Linus Torvalds
Date: Sun Jan 04 2004 - 23:38:05 EST




On Sun, 4 Jan 2004, Bill Davidsen wrote:
>
> Your example, which I quoted, *is* standard C. And it avoids duplication
> of code without extra variables, and is readable. We both agreed it was
> standard, why have you canged your mind?

Oh, that one. I thought you were talking about the gcc extension.

My version is not what I'd call really readable unless you actually have
an agenda to access the variable though a pointer. In fact, the only case
where I have actually seen constructs like that is literally when you want
to avoid a branch for some specific reason, and you do something like
this:

int branchless_code(int *ptr)
{
int dummy;

...
*(ptr ? ptr : &dummy) = value;
...
}

it you'd rather do a unconditional store through a conditional pointer
than have a conditional store, and you use a dummy "sink" variable to take
the store if the condition isn't true.

Some compilers apparently generate this kind of code internally from
conditional statements. I've never seen gcc do it, though.

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/