Solved

Simple syntax question

Posted on 2004-08-02
5
253 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
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

860 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