[LCP]wrapper around strcmp

sasidhar p psasidhar at hotmail.com
Thu May 23 11:55:06 UTC 2002


Hi Michael,
  Thanks for your reply.

>Do you want it to hang the program? No? Then don't use your second
>version because that's what it will do (if either of the strings is
>NULL). That's the purpose of assertions, easy debugging of exceptional
>conditions you expect never to exist and which your code cannot handle.

Definitely, I dont want my program to halt. Actually I myself am not clear 
about the usage of 'assert'. 'assert.h' has this macro,

#define assert(EX) (void)((EX)||(__assert(#EX, __FILE__, __LINE__),0))

I didnt understand this. Can you please say more on this?

I frequently use various string.h functions in my application which runs 
into hundreds of lines of code. My observation is, the reason behind 
ocassional core dumps is one of the arguments to these string functions 
becoming NULL. Generally, the arguments will not be null, but under very 
exceptional conditions, they might be null. What is the best way of avoiding 
'core dumps' in such cases. Am I right in using an 'assert' in such cases. 
But even if I use 'assert', it also dumps core, like the non-assert version, 
the only difference being we get a helpful message. So, does it really serve 
my purpose. Any thoughts on this??

>Maybe you do want it to return false if BOTH strings are NULL (did you 
> >consider that possibility and whether you might in that case prefer to 
> >return "true").

This is an interesting aspect which I overlooked. Thanks for pointing it 
out.

>You didn't indicate how you intended to "keep" these.

I generally keep all my general purpose routines in a file, something like 
$HOME/shared/strutils.h and include this one into my application.


English is not my first language, so, please do bear with me if I am not 
clear.

Thanks,
Sasi.




_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com





More information about the linuxCprogramming mailing list