Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Extra libraries, Code snippets, applications etc. » C++ language problems and code snippets » Time for little quiz!
Re: Time for little quiz! [message #2271 is a reply to message #2269] Wed, 05 April 2006 15:50 Go to previous messageGo to previous message
hojtsy is currently offline  hojtsy
Messages: 241
Registered: January 2006
Location: Budapest, Hungary
Experienced Member
victorb wrote on Wed, 05 April 2006 09:04

I remove my vote for "colorcount += (q != 0)" adding an int with a boolean is not so nice...
At least it has standard-defined behaviour, which is an improvement over shifting negative numbers.

victorb wrote on Wed, 05 April 2006 09:04


And I propose suggested #4: "colorcount += (q)?1:0;" (this will generate the same code as #3 with GCC).
You don't really need parenthesis there: "colorcount += q ? 1 : 0;" First I thought that this variant may generate a branch.

victorb wrote on Wed, 05 April 2006 09:04

Funny to see how many post such a small statement "(-q >> 31) & 1" could generate Razz
I think that the big challenge is not to write fast & obfuscated code, but rather write fast and clean code. This example is small enough to test whether this is possible in C if you take the "fast" aspect to the extreme. I see the obfuscated version as practically assembly magic, even if it is written with C statements: the question is whether there is a C++ standard-conformant solution with the same or better runtime performance.
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: STL multimap
Next Topic: explanation of c++ typedef line
Goto Forum:
  


Current Time: Wed Apr 30 10:47:32 CEST 2025

Total time taken to generate the page: 0.01105 seconds