Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.

Ternary operators

This topic is 5826 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Not faster, but sometimes easier to read/understand. Stuff like checking for the max of two numbers (a > b ? a : b), that sorta thing works wonders for readability. But using it in place of a general if-then statement can make code harder to read as well. My suggestion: use them if you''re confortable with them, and preferably only when they improve readability/ease of understanding of the code''s purpose.

Share this post

Link to post
Share on other sites
Original post by Melraidin
Not faster, but sometimes easier to read/understand.

If your CPU architecture supports predicated operations, then it may be faster, as it is 'more obvious' to the compiler what to do with it.

Be aware of the constraints of the operator though. For instance, the expression (bool)b:‌(double)d?(long)l is always of type double.

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]

[edited by - Fruny on June 7, 2002 11:36:33 AM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!