Solved

Simple syntax question

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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 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.

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now