|
Method (1) is dangerous - it requires that GetValue() has no side-effects. This makes for code that's hard to maintain.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
First, the line else if(myArray.GetAt(i).GetValue()==2) { Function2(); } } has an extra brace at the end.
In actual performance the two are identical since they compile to the same thing (at least in VC++ 7.1, but likely also in VC++ 6.0.)
Incidentally, using a switch statement is slightly slower. If there were additional cases, that could change.
[EDIT: At Tim correctly points out, my answer is correct only to the narrow stipulation given. Since GetValue() could involve more than the return of a simple value, it is best to get the value first then test it. The exception would be IF side effects are documented and each test depends on those side effects, though that would be a very odd solution indeed.]
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
What if the definition of GetValue is in another CPP module? Depending on the link time optimization, that code might not be hoisted into the main routine. Thus the multiple GetValue version would not result in the same code.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
That wasn't part of his stipulated conditions.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Nor was the implementation of the routine being inside the same cpp or made inline.
The only reason I bring this up is because you don't tell the full story. What you said is totally true but only under certain conditions.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
In general, you should use the second version.
When you have full knowledge of how GetValue is implemented, you can decide which is better. However, that makes caller dependent on the implementation of GetValue. If you ever need to change the implementation, any performance decisions might come back to haunt you. You really shouldn't be depending on GetValue being implemented as it is. Thus that makes the second version the better option.
You should always try to keep relationships between two classes limited to interface only and never the actual implementation. You can't always do this, but when you can, it is best that you do.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Is it free to use the MFC source code however you want, or is that off limits. I don't want to use MFC, but I would like to use bits and pieces of it, like CRect etc. Is this legal, or is it violating any copyrights?
|
|
|
|
|
It's completely legal on the condition that you don't use it to write, and I presume sell, a class library or otherwise represent the code as your own.
Microsoft also requests that you don't compile the new results with the same name as the current MFC libraries.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Hi All,
I am trying to send data from my client to my server through an RPC call in Unix C. I am getting following error:
ServerNameHere: RPC: Unable to send; errno = Bad file number; Illegal file descriptor
I am unaware of nitty gritties of RPC, can anyone help?
I need urgent help. Thanks in advance for any help provided.
Just to elloborate on problem, this error normally comes when I try sending some data 2nd time. I am sending different data each time(taken by user input) in a loop.
Regards,
Ahsan
|
|
|
|
|
Knock Knock...
Anybody home? Someone please answer.
|
|
|
|
|
This is a Visual C++ forum on a site with an almost exclusive Microsoft bias. You're not likely to get help with a UNIX RPC problem here, I'm afraid.
Software Zen: delete this;
|
|
|
|
|
I am a newb to programming, so I use the MFC wizard in VC++ 2003. I would like to have access to the WindowProc function (the function that recieves all the messages), but it is locked. Does anyone know how I could edit the WindowProc function? Anyone that could help, that would be great.
|
|
|
|
|
I need stop the program,
<br />
<br />
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {<br />
if (stricmp(lpCmdLine, "-noautorun") == 0) {<br />
autorun(); <br />
i cant juse break; <br />
<br />
}else if (lpCmdLine == NULL || _tcslen(lpCmdLine) == 0) {<br />
<br />
MessageBox(NULL, _T("No switch specified"), g_pszCaption, MB_OK | MB_ICONEXCLAMATION);<br />
return 0;<br />
}<br />
<br />
void autorun(){<br />
if void autorun() ends, <br />
the program needs to stop running <br />
<br />
i cant juse return 0;<br />
<br />
return 0;<br />
}<br />
error C2562: 'autorun' : 'void' function returning a value<br />
<br />
thanx for helping me
Greets Jeroen
|
|
|
|
|
Obviously voids can't return a value but I think you could use ExitProcess API or maybe TerminateProcess API. Try this link
-Ryan M.
|
|
|
|
|
Thanx ryan M.
<br />
void autorun () {<br />
<br />
ExitProcess(0); <br />
}}<br />
Jeroen .b
|
|
|
|
|
don't exit() function work too ?
TOXCCT >>> GEII power
|
|
|
|
|
Sorry, I don't know if this autorun() -function is something special, but if you have a function which has void as return type you can just use the instruction return; to end the function (without any value) or just leave out the return instruction completely.
Hope it helps...
Regards, mYkel
|
|
|
|
|
no i cant use return;
or leave out the return instruction
it gives errors with other functions
ExitProcess(0); works good
Greets jeroen
thanx for your time
|
|
|
|
|
|
he CANNOT return a value if the function is told as "not returning a value", which is the meaning of void here !!!
TOXCCT >>> GEII power
|
|
|
|
|
<br />
void autorun (void) {<br />
<br />
}<br />
exit (0);<br />
}<br />
Jeroen.b
|
|
|
|
|
i kow it works, but actually, i'd like to know the difference between ExitProcess() and exit()
TOXCCT >>> GEII power
|
|
|
|
|
On an Intel architecture, do the following two lines mean the same thing, or for that matter, is the first even valid? I'm struggling with inconsistent lecture notes here and I'm being driven mad!
1) move %eax, 40-16(%fp)
2) move %eax, 40-16(%ebx)
Not knowing Intel assembly very well, I assume that the second operand is using relative addressing, though I'm also not sure about the meaning of 40-16, if anyone could shed any light>
Thanks!
--
Andrew.
|
|
|
|
|
why did you use %fp? is that even a register.? I am not sure if it is even valid but then again i have only been doing assembly for a month now.
-Ryan M.
|
|
|
|
|
I'm pretty sure %fp isn't a register. It's not my code, it's from some lecture notes I'm trying to understand, but am struggling to since I don't know where the %fp comes from.
I presume it's referring to teh frame pointer, which points to the place in the stack where the frame pointer is held for the previous stack frame.
Do you know what the 40-16(%ebx) does?
(I translated %fp into %ebx myself, there is no mention of %ebx in the notes... weird!).
--
Andrew.
|
|
|
|