Oh my god... The MFC MESSAGE_MAP... How could i miss this rape on #define-macros and the whole C++ Language...
C3D1
Posts
-
C++ expression(s) -
C++ expression(s)isn't that a C++ 11 feature? I'm currently using the VC6 compiler... There is no C++ 11 :java: ;P
-
C++ expression(s)Today i found some really weird expression in some C++-code
if(++(k=j) != node.end())
{
if("something" == *k)
doSomething();
else if("something other" == *k)
doSomethingOther();
}and just ~30 lines below that weird if statement i found this:
k = j;
if(++k != node.end())
{
if("something" == *k)
doSomething();
else if("something other" == *k)
doSomethingOther();
}why always so weird? Why don' to it in an nice way
k = j + 1;
if(k != node.end())
{
if("something" == *k)
doSomething();
else if("something other" == *k)
doSomethingOther();
}In some other code a few days ago i found this
n[idx++] = a[++idx2]++;
where both, a and n, are defined as
void*
What are the ugliest C++ expressions that have you seen in the last few weeks/months -
Fun with pointers in C++totally agree with you. But always use const can cause some other problems. I personally try to avoid "pointer-getter-functions" but when i have to use, i do something like this:
class Foo
{
private:
int m_nA;public:
int* GetAPtr() { return &m_nA; }
const int& GetA() const { return m_nA; }
void SetA(int nA) { ASSERT(IsValid(nA)); m_nA = nA; }
};And if i have to use the pointer-getter i have to write
Ptr
explicit. So i see extremly fast that*GetAPtr() = *GetBPtr();
is nonesense, and if you try to do
GetA() = GetB();
you get a compiler-error Maybe my way overshot the mark a litte bit. ;P :-\
-
Fun with pointers in C++Sorry, that's not my code, an i cant change it. I just saw it in some code and where surprised what's that :D Returning references would make it much harder to read:
GetA() = GetB()
looks like What the hell? Assignment to a Function? :omg: :wtf:
-
Fun with pointers in C++Today i come across this two lines of code (i changed the naming of the functions):
// ...
if(GetA() && GetB())
*GetA() = *GetB();
// ...took me nearly two hours of figuring out WHY DOES THIS CODE WORK, since i realised that
GetA()
returns a Pointer and Pointers are IValue... Looked deeper inside the code, i found aSetA(int)
-Method... Why to use something like*GetA() = *GetB()
if you could use
SetA(*GetB())
-
Friday Programming ChallengeJust to make sure i'm understanding everything right. You want to convert CIDR notation to dotted decimal?! My approach is to convert the CIDR to a binary string (eg. /8 = 11111111000000000000000000000000), then split this string to the octets in an array (eg. [0]=11111111 [1]=00000000 [2]=00000000 [3]=00000000) and then converting each octet to decimal. Sample source in C#:
public enum IP_TYPE
{
IPv4
, IPv6
}public String convertCIDR2DottedDecimal(int nCIDR, IP_TYPE eType)
{
// Build Binary String
int nBits = (eType == IP_TYPE.IPv4) ? 32 : 128;
String sBinary = "";for(int nIdx = nCIDR - 1; nIdx >= 0; nIdx--) sBinary += "1"; for(int nIdx = nBits - nCIDR; nIdx >= 0; nIdx--) sBinary += "0"; // Split Binary String to Octets int nOctets = (eType == IP\_TYPE.IPv4) ? 4 : 16; String\[\] aOctets = new String\[nOctets\]; for(int nIdx = 0; nIdx < nOctets; nIdx++) { String sOctet = ""; for(int nOctetIdx = 0; nOctetIdx < 8; nOctetIdx++) { sOctet += sBinary\[nOctetIdx\]; } sBinary = sBinary.Substring(8); // Convert each Octet to Decimal aOctets\[nIdx\] = "" + Convert.ToInt32(aOctets\[nIdx\], 2); } return String.Join(".", aOctets);
}
-
Launch Safari from another app then Autofill username and passwordto my knowledge this is not possible. I saw some password tools (like 1Password, LastPass) on the appstore that opens up a website on an internal browser and then fill in the username and password. But to my knowledge apple doesen't allow IPC between most of the Apps. The only place where Apps are communicating is AppleHealth where 3th party apps could write to AppleHealth. If you find a way to opening up safari and then fill in the user and password boxes i'm extremly interested in the solution! :)
-
Are MFC Timer(s) bad for performance in large projects (Vc++)Hey out there, i'm heared that the use of timers in large projects is bad for performace. So is this true? I'm wondering, because i have done a new control using VC++/MFC and i use one timer in there. The timer only is created and the first time it's called i terminate it. Now someone said to me that i sould use ::GetTickCount() instead and save the first value and compare it again and again. It look more performance hungry than my timer solution. So what's your oppinion? Please don't answer something like i should do a test, i haven't so much time to test such things. And please answer only real facts and not only stuff like "i like timers more because i like it more" or "i like the TickCount solution more". Hope for a good discussion :)
-
Are MFC Timer(s) bad for performance in large projects (Vc++)Hey out there, i'm heared that the use of timers in large projects is bad for performace. So is this true? I'm wondering, because i have done a new control using VC++/MFC and i use one timer in there. The timer only is created and the first time it's called i terminate it. Now someone said to me that i sould use ::GetTickCount() instead and save the first value and compare it again and again. It look more performance hungry than my timer solution. So what's your oppinion? Please don't answer something like i should do a test, i haven't so much time to test such things. And please answer only real facts and not only stuff like "i like timers more because i like it more" or "i like the TickCount solution more". Hope for a good discussion :)