Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Simple syntax question

Posted on 2004-08-02
5
Medium Priority
?
278 Views
Last Modified: 2010-04-01
Please describe what this does:

byIndex = (m_csBitmaps[2].hBitmap == NULL ? 0 : 2);

Is it some kind of "if then else" shorthand?
0
Comment
Question by:PMH4514
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11697780
Yes, it is some kind of if...then...else

value = condition ? return_for_true : return_for_false;

It is a common operator in many languages.
0
 
LVL 22

Expert Comment

by:grg99
ID: 11698375
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;

0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 100 total points
ID: 11698445
Equivalent C expression:

if (m_csBitmaps[2].hBitmap == NULL)
      byIndex = 0;
else
      byIndex = 2;

Shorter expression:

if (!m_csBitmaps[2].hBitmap)
      byIndex = 0;
else
      byIndex = 2;
0
 

Author Comment

by:PMH4514
ID: 11698517
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)

0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11698541
> 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.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question