Solved

Simple syntax question

Posted on 2004-08-02
5
259 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 25 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

726 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