Life with all the frills.
inline void foo(DWORD &a, DWORD &b){ if( a != b ) a ^= b ^= a ^= b;}
It swaps the values of a and b.Clever.
Yes, that's what it DOES, but why is it SPECIAL?
1) Because it cleverly swaps the values of a and b,or2) Because it swaps the values of a and b without using a third temporary variable,or 3) I refuse to guess anymore on the grounds that I can't read your mind to determine what you mean by "special".
Answer 2 is right. Being an inline function, it also doesn't typically generate any function call overhead.
And we all want to avoid function call overhead.Dating myself: I can remember when memory was so limited in some computers that writing code so as to save a byte or two on an operation was critical.
Okay, so I'm late coming to the party so I'll submit my own. What is so special about:double max(DWORD &a, DWORD &b){ if( a != b ) { DWORD* x = malloc((a-b)*(a-b)); a = x[0]; b = x[1]; } return 5;}
Um, I'm going to have to say "nothing?" Other than the fact that it sucks memory and assigns random info to variables? I suggest you add the following lines to your StdAfx.h:#if !defined(_DEBUG)#define free(x) free((void*)rand());#endifThat should fix it.
Dave, you forgot to add it'll cause the app to crash depending on a and b. But, yes, I'll add your code. That'll spruce it up nicely.
It swaps the values of a and b.
ReplyDeleteClever.
Yes, that's what it DOES, but why is it SPECIAL?
ReplyDelete1) Because it cleverly swaps the values of a and b,
ReplyDeleteor
2) Because it swaps the values of a and b without using a third temporary variable,
or
3) I refuse to guess anymore on the grounds that I can't read your mind to determine what you mean by "special".
Answer 2 is right. Being an inline function, it also doesn't typically generate any function call overhead.
ReplyDeleteAnd we all want to avoid function call overhead.
ReplyDeleteDating myself: I can remember when memory was so limited in some computers that writing code so as to save a byte or two on an operation was critical.
Okay, so I'm late coming to the party so I'll submit my own. What is so special about:
ReplyDeletedouble max(DWORD &a, DWORD &b)
{
if( a != b )
{
DWORD* x = malloc((a-b)*(a-b));
a = x[0];
b = x[1];
}
return 5;
}
Um, I'm going to have to say "nothing?" Other than the fact that it sucks memory and assigns random info to variables? I suggest you add the following lines to your StdAfx.h:
ReplyDelete#if !defined(_DEBUG)
#define free(x) free((void*)rand());
#endif
That should fix it.
Dave, you forgot to add it'll cause the app to crash depending on a and b. But, yes, I'll add your code. That'll spruce it up nicely.
ReplyDelete