That's illegal, and shouldn't compile.
Weird. I've been relying on "gcc -ansi -pedantic" too much, then.
Why? The compiler is far more capable than you of counting the
exact frequencies.
The key word is "know". With regards to knowing, the compiler
is severely disadvantaged.
(Your example reminds me of Duff's device. Or how to abuse
switch statments.)
I'm not suggesting anything of the sort. I'm not relying on fall
through, or jumping into the middle of switches. I'm saying that
if one behaviour happens 30,000,000 times more often than three
other behaviours combined, then it can make sense to put those
other three in an else block. So that there is only one condition
before getting to the most commonly executed code.
Yes, I do.
It would be necessary to examine the exact code you were
comparing, and then look at the generated code to be sure. For
something like the above, I'd imagine that something like:
switch ( x % 8 )
{
// ...
}
would be fastest.
That's what I imagined. I was wrong. At least with one
compiler, one platform, etc.
--Jonathan