Well, looks like you've answered 1, 5, 6, 7.
QUOTE
So, a question now would be, how is this done better?
and i leave that up to you.
The question was to DO it, and not to do it efficiently, or fast, or small code or whatever.
You want small, efficient code, use branches!
About the question, yes true, but....
The point of branch free code is sorta to be efficient. The idea is that branches are terrible for pipelined processors (which all modern CPUs are). So if you can code something equivalently, but avoid branches, you can often get a gain in efficiency.
So, since those problems are solved, I'd like to up the ante a little. :ph34r:
Solve challenge 1, but this time without overwriting any data that you've defined or allocated space for (you being the important part here). Relating this to the solution of problem 1, the string array that is modified and reprinted will be in violation of the rules for challenge #8. Also, the loop index which is defined and modified by that solution will also be in violation of the rules for challenge #8. Now, that's not to say your program can't make use of variables. You just can't *modify* any that YOU have defined (this includes both data you've defined, and the data pointed to by pointers you've defined). Calling a library function like printf will use some of it's own local variables, but this should be of no concern and will not be considered against the rules. You must not call a library function that writes to a buffer you've defined. Ex:
char buff[64];
snprintf(buff, 64, "Writing data to a buffer you've defined!"); // Against the rules!
printf("Hello World!"); // Nothing wrong with this
char string1 = "This is a string";
printf("%s", string1); // Nothing wrong with this either
As an added difficulty (maybe?), I'd like to add a rule against using using library functions that allocate a buffer and fill it before returning the pointer to you. That is, something along the lines of:
char *string2 = CopyString(string1); // Against the rules
string2[1] = "\n"; // Clearly against the above rules about writing to data through a pointer you've defined.
char *string3 = CopyAndTranslate(string1); // Also against the rules
Basically, all this is to say any memory being written to at run time MUST be done by standard C++ library functions, and you must gain no direct access to such memory. (All such memory has it's use confined to the standard C++ library function that uses it, and no pointers to such memory are returned).
Note: This challenge is likely much harder than the original, and will definately require some rethinking for a solution.
9) Solve challenge #6 with at most 5 assembly instructions. (You *should* need less than this).
10) Solve challegne #7 with at most 5 assembly instructions. (You *should* need less than this).
*Following is a repost of a challenge that was lost when the forums went down*
(Let's see if anyone remembers the answer
11) In C++, the result of writing the following code:
cout << 2["Hello World"] << endl;
will be ...?