PMH4514
asked on
Simple syntax question
Please describe what this does:
byIndex = (m_csBitmaps[2].hBitmap == NULL ? 0 : 2);
Is it some kind of "if then else" shorthand?
byIndex = (m_csBitmaps[2].hBitmap == NULL ? 0 : 2);
Is it some kind of "if then else" shorthand?
It's a bit of if/the/else shorthand for expressions. A bit cryptic.
In this case it says: if the .hBitMap is NULL, this side of the equals sign has a "0", otherwise it has a "2".
In other less cryptic (altho dead) languiages like Algol, youd say the same thing in a much less head-scratching form:
byIndex := if m_csBitmaps[2].hBitmap = NULL then 0 else 2;
In this case it says: if the .hBitMap is NULL, this side of the equals sign has a "0", otherwise it has a "2".
In other less cryptic (altho dead) languiages like Algol, youd say the same thing in a much less head-scratching form:
byIndex := if m_csBitmaps[2].hBitmap = NULL then 0 else 2;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks Jamie.. I was pretty sure of that.. I've seen it before, I tend to write more verbose code.. that's going to change now that I'm doing lower level stuff.. I wonder if the shorthand is any faster once compiled? (if so it's probably not even perceptable even with timer scripts)
> I wonder if the shorthand is any faster once compiled?
That is a compiler-dependent feature, if you are very interested, you have to some a performance test by yourself.
That is a compiler-dependent feature, if you are very interested, you have to some a performance test by yourself.
value = condition ? return_for_true : return_for_false;
It is a common operator in many languages.