|
There is a good answer to this question, but you, as the programmer, have to make a design decision about Foo() . The question you should ask is this:
Is it legal for another programmer to call Foo() with a null pointer?
or phrased differently:
If a programmer passed NULL to Foo() , would that be a bug in the calling code?
If you decide that getting NULL is an illegal condition (based on how you designed Foo() ) and indicates a bug in the calling function, then you should use ASSERT . If, on the other hand, Foo() 's design makes getting a NULL pointer reasonable, and would not indicate a bug in the caller, then you should be using the if .
You'd use both when getting a NULL would indicate a bug, and when you'd still want the code to behave intelligently even when it gets garbage. The typical scenario would be aircraft controller software, or radiation machine software. Bugs in either of these pieces of software could be deadly and so you'd keep the if just in case a bug makes it into the final code. Hopefully the ASSERT would alert you to the bug long before then.
Probably the best way to figure out whether to use an ASSERT or an if is to follow this guideline:
Completely finish the function as you intend to ship it. Once you're convinced that you've got the code as you plan to ship it, _only then_ do you add assertions (and debug code), _without_ changing what your ship code does.
Remember, debug code is strictly _extra_ code.
Using this guideline, you can see that if your ship code has to handle NULL pointers, then you have to use an if statement to handle the NULL pointer. If the ship code doesn't have to handle the NULL pointer, then you can ASSERT that getting one is illegal so that it alerts callers to their bugs.
The main difference between if tests and assertions is that assertions should test for conditions that you expect *never* to happen; if tests are for conditions that you plan to deal with. Assertions should not take the place of normal error-processing code. They should be used to flush out defects in your code. Put differently, an assertion should never fire unless there is a defect.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
-- modified at 11:51 Thursday 6th April, 2006
|
|
|
|
|
Hi All,
I have a application that uses buttons, combo box's etc. Using VS2005 Express in debug mode, all the controls are in the XP theme. But if I build the same image in release mode, the controls revert back to 95/98 controls. Now if I make the linker not embed the manifest, then I add the following lines to the manifest file:
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="x86" publicKeyToken="6595b64144ccf1df" language="*"></assemblyIdentity>
</dependentAssembly>
</dependency>
And all is well. But now, how do I get the linker to embed it in the exe?
regards,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proof programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
You add the manifest file to the executable's resources with a specific Resource Type (that I cannot remember at the moment, but a Google search should help you out here).
You could also place the manifest file in the same run directory as the executable when it is deployed and that will work, too.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
Thanks. I have taken the later option, but now run against the problem where people will complain if they have to copy 2 files (the previous version was just an exe).
Do you know how to add it to the resources using VS2005 Express?
Express complains that it is not able to edit resources when I tried to open a .rc file.
regards,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proof programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
Hi,
Are there any Artices or Code to implement Windows Xp Style Explorer Bar in and MDI application.
Thanks in Before
JamesRocky.
|
|
|
|
|
Following is the code from MFC frame work,
if I call "pThread->InitInstance()" method application is calling CWinApp->InitInsatnce() method,
CWinThread is super class of CWinApp when I call with super class object "InitInsatnce" method
it should call CWinThread:InitInstance method,
how it is going to sub class,
can any body explain to me
thanks,
Siva
---------------------------------------------------------------------
int AFXAPI AfxWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow)
{
ASSERT(hPrevInstance == NULL);
int nReturnCode = -1;
CWinThread* pThread = AfxGetThread();
CWinApp* pApp = AfxGetApp();
// AFX internal initialization
if (!AfxWinInit(hInstance, hPrevInstance, lpCmdLine, nCmdShow))
goto InitFailure;
// App global initializations (rare)
if (pApp != NULL && !pApp->InitApplication())
goto InitFailure;
// Perform specific initializations
if (pThread->InitInstance())
{
if (pThread->m_pMainWnd != NULL)
{
TRACE0("Warning: Destroying non-NULL m_pMainWnd\n");
pThread->m_pMainWnd->DestroyWindow();
}
nReturnCode = pThread->ExitInstance();
goto InitFailure;
}
nReturnCode = pThread->Run();
InitFailure:
#ifdef _DEBUG
// Check for missing AfxLockTempMap calls
if (AfxGetModuleThreadState()->m_nTempMapLock != 0)
{
TRACE1("Warning: Temp map lock count non-zero (%ld).\n",
AfxGetModuleThreadState()->m_nTempMapLock);
}
AfxLockTempMaps();
AfxUnlockTempMaps(-1);
#endif
AfxWinTerm();
return nReturnCode;
}
---------------------------------------------------------------------------------
|
|
|
|
|
Siva Sankar Koyi wrote: if I call "pThread->InitInstance()" method...
Why would you want to call this method directly? It is a virtual method that is intended to be overridden.
Other than that, I'm not really sure what it is that you are asking.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
I have one server and three clients, Messages come as XML format from client1 and I have to send it to client2 (without knowing the content of the message)through server and then send back the ACK to client1 when client2 gives it to server, Now the problem is that if client1 sends a particular message to server(say if the message is sign on request)I should send it to client3 through rotor and internet and then get the response back from cliet3 and send it to client1 and client2( )
I have a socket class written for this problem but I do not know how to handle the WHOLE THING. I guess I hould check the content of the message that comes from client1 in my APIClass and then use different sockets to send it to different clients.
Please help me to solve this issue
Nahitannahi@yahoo.ca
|
|
|
|
|
Sounds like you have to define a nifty little protocol of your own, where you can distinguish the different message types from each other. The payload of each packet could be the XML info.
Or perhaps I didn't understand your problem correctly...
Hope it helps anyway
--
Roger
It's supposed to be hard, otherwise anybody could do it!
|
|
|
|
|
Hi there.
----Client 1
------ |
Server| --------+---Client 2
------ |
----Client 3
Two solutions come to mind. My assumptions
. your server is acting as a proxy - i.e. clients 1,2,3 only talk to the server, not directly to each other.
. client 1 is only ever a socket client, it does not listen for a connection
. client 2,3 have sockets open waiting for a connection from the server.
Firstly, if you want one socket listening on your server, you will have to inspect the messages.
No sign message
The steps,
. Client 1 sends message
. Server (starting a new thread for the connection) inspects message and opens a connection a connection to client 2 and sends message to client 2
. Client 2 ACKS message to Server
. Server ACKS message to Client 1
Sign on request message
. Client 1 sends message
. Server (starting a new thread for the connection) inspects message and opens a connection a connection to client 3 and sends message to client 3
. Client 3 signs and returns to the message to the server.
. Server opens a connection a connection to client 2 and sends signed message to client 2
. Client 2 ACKS message to Server
. Server ACKS message to Client 1
Alternatively, if you use two different sockets on your server, one for signed messages, one for normal messages, then you will not have to inspect the messages on the server.
Remember to use threads when accepting your socket connections.
Hope this helps concrete your design.
Cheers
|
|
|
|
|
Tnx for the help,
Here what I have is that in the code I have a messagetype as PKT_MSGTYPE_FORM_DATA which I receive from client1 (a small machine programmed by micro C a wireless thing working like a intract machine) my program recognizes this Form if it's value is 0F(Hex) and if it's first byte (the string) is number 04H it should send the packet to client3 otherwise send to client2,
could you help me to write the C code for this problem?
also as I am new in socket programming, I am not sure how to handle all the socket thread stuff
SOS
tnx a lot!
nahitannahi@yahoo.ca
|
|
|
|
|
Hello.
I'm not an artist, but I need some graphics for icons, buttons, bitmaps and want all this stuff to look professional.
How you solving that problems?
If existing any good icon or bmp libraries for non-artist programmer?
Or if you paint icons bmps by own what editor you use?
Thanks.
|
|
|
|
|
|
Sounds like we are the opposites, I am a graphic designer and know only the basics of programing. Needless to say I am always being complemented on the good graphics in my games but not so much for the playability.
|
|
|
|
|
Also check out http://iconbazaar.com/[^].
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
|
nope nibu...
i posted this link first, but removed it, because the author specifies that these icons are for web application only...
|
|
|
|
|
But why they cannot be used with web applications. Any specific issues!
Nibu thomas
Software Developer
|
|
|
|
|
i don't get you.
i tell you that the icons are for web applications only, and you ask me why they ca't be used for web apps ?
>> Any specific issues!
not issues, but license restrictions.
|
|
|
|
|
Heh sorry buddy...
I misread your post. I just put a 'not' before 'for'. Sometimes my eyes has this tendency to modify posts.
Why two copies of the same message!;P
Nibu thomas
Software Developer
|
|
|
|
|
Nibu thomas wrote: Why two copies of the same message!
because whenever i delete the wrong one, CP keeps it there
|
|
|
|
|
|
hey, seems to have disapeared... can you see it ?
|
|
|
|
|
v2.0 wrote: hey, seems to have disapeared... can you see it ?
No,Gone! Mission Success...
Nibu thomas
Software Developer
|
|
|
|
|
I think it's too small sizes.
If there is place to read about technology of making own bmps?
|
|
|
|