|
Example I don't get |
weapon_S
Member #7,859
October 2006
|
Well it's not the examples themselves I don't get, but... to the point;
Now, I'm probably not being too bright, but what is that last line? I know about set_color_depth, but this seems weird. I mean "||", what does this do? |
gnolam
Member #2,030
March 2002
|
Quote: I mean "||", what does this do? ... that's an OR. -- |
weapon_S
Member #7,859
October 2006
|
Hilarious... T_T |
Ceagon Xylas
Member #5,495
February 2005
|
Tried using google? |
Evert
Member #794
November 2000
|
Quote: Now, I'm probably not being too bright, but what is that last line? I know about set_color_depth, but this seems weird. I mean "||", what does this do?
A feature of short-circuit logic. If the first operand evaluates to TRUE, the second operand is not evaluated at all (since its value is not important for wether the end result is TRUE or FALSE). |
Peter Wang
Member #23
April 2000
|
Quote: I'm also not sure if the C standard guarentees the order of evaluation to be left to right. For this, yes.
|
gnolam
Member #2,030
March 2002
|
It was a serious answer. -- |
miran
Member #2,407
June 2002
|
Quote: Tried using google? How does one use google to find what || means? -- |
tobing
Member #5,213
November 2004
|
What it does: If the first fails (i.e. evaluates to false) then the second is evaluated, if that fails then the third is evaluated etc. Would be equivalent to if(!depth_select(32)) if(!depth_select(24)) if(!depth_select(16)) depth_select(15);
|
Karadoc ~~
Member #2,749
September 2002
|
miran said: [quote Ceagon Xylas]Tried using google?
How does one use google to find what || means? ----------- |
weapon_S
Member #7,859
October 2006
|
Ah, yes, thanks. |
gnolam
Member #2,030
March 2002
|
Quote: I.e. there's no compiler which scrambles the order for optimization? If they do, they're broken. Left-to-right order and minimal evaluation is guaranteed by the standard. -- |
Audric
Member #907
January 2001
|
What gnolam says. if (bmp != NULL && bmp->width > SCR_WIDTH) {/*do stuff*/} The second term would horribly break if it was evaluated before of the first - or when the first was already known to be false. edit: For the record, AFAIK, the only non-determined order of evaluation is functions arguments: i=0; printf ("%d %d\n", i++, i++); It could print "1 2" or "2 1". |
Evert
Member #794
November 2000
|
For the record, I wouldn't consider doing that in a C program to be good coding style... |
Kikaru
Member #7,616
August 2006
|
Putting "||" into Google shows nothing. |
Thomas Fjellstrom
Member #476
June 2000
|
Or you could use your head and search for C Operator "or". -- |
Paul whoknows
Member #5,081
September 2004
|
This is how it looks like ____ "The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner. |
Ceagon Xylas
Member #5,495
February 2005
|
Well, wasn't trying to be rude, but I googled 'C++ operator' As you would expect, it came up with a list of operators including ||, the or operator... This page also proceeded to explain what that operator does. weapon_S said: I know it's probably a stupid question, because it is such a basic operator He apparently knew what operators were. Karadoc ~~ said: If you don't want to help, just don't help. There is no need to announce that you aren't going to help. I guess my help was: I found it by this simple method which I'll now remind you to use. It discourages having it handed to you. |
Johan Halmén
Member #1,550
September 2001
|
Don't ever adapt that coding style. It is just stupid, even though it looks neat. Depend more on your compiler's ability to optimize your nested ifs. IIRC there's a compiler option that makes all comparisons evaluated in a line like that. If you ever need to set that option for any reason, you don't want your program to run in wrong colour depth. I avoid the following, too: if (b == 0 || a / b > foo) bar(); Instead: if (b == 0) bar(); else if (a / b > foo) bar(); For same reason. [edit] Quote: Well, wasn't trying to be rude, but I googled 'C++ operator' I remember when I first saw || in the code (might have been just |), ages ago. Even though I knew some C and had coded simple games, I just didn't recognise that it was an operator. I hardly knew the word 'operator'. OTOH there was no Google at that time. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest. |
X-G
Member #856
December 2000
|
-- |
|