Didn't find your answer? Ask the community — no account required.
R
Rob Gaddi
Hey, don't knock it. On a RISC machine, that difference might save you two, maybe even three instructions.
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order. See above to fix.
J
Joe Chisolm
Probably what the orignal intent, other than just being a smart ass, is to try and help a bad compiler with the index multiplies. A good optimizer will fix both code sets to be the same or very close. The first example might save a stack save/load if you have a lot of registers to play with.
The Ewww factor is very high, enough to send the person back to beginning typing school to learn to use more than 2 fingers.
Joe
Republic of Texas
A
Andrew Reilly
You're complaining about the spurious parentheses around adc_ping_pong, on the first line, right? ;-)
Cheers,
Andrew
A
Arlet Ottens
You could introduce a temporary variable, and make it a lot more readable:
ha ha , that is just what I noticed, And I write stuff a bit like that sometimes,,,
AFAIK they are equivalent and should produce the same optimised object code.
John Devereux
H
Hans-Bernhard Bröker
I'll call, and raise you a
fill_ix] = raw\ _data;
If you're going to try a "reductio ad absurdum", why stop short? Might as well go all the way to make it truly absurd.
Of course it will compile --- it'll even work. Which does beg the question: why the "Ewww"?
Seriously, though, nobody forces anyone to write code like that first snippet (much less mine), and rather few programmers would. Most people would only consider the conditional operator for the right-hand side of an assignment, or function arguments, i.e. for making rvalues, not lvalues.
But then again, in a pinch the compiler might, for some strange reason, compile denser/faster code from it, and if that saves the day, there's nothing wrong with having that option, is there?
And if you're really uncomfortable with that rather dense notation, there are always in-between options like those shown by others here. Following the principle of separating things that differ from things that don't (in other words: don't copy-paste, concentrate!), I would lean towards this one:
I think if you are going to use the conditional operator you *must* nest them at least nine deep. I did that once about twenty years ago, the boss emitted steam.
Well worth it.
Mike
D
Datesfat Chicks
You can probably rigorously prove that any if-else construct involving assignment to a single variable can be represented with nested C ternary operators.
DFC
T
tim....
Only if you have a crap compiler :-(
tim
Join the Discussion
Have something to add? Share your thoughts — no account required.
Didn't find your answer?
Ask the community — no account required
Report Content
You are reporting this content to the moderators. They will look at it
ASAP.