Subj : Re: string comparison To : borland.public.cpp.borlandcpp From : "Base8" Date : Mon Nov 24 2003 03:50 pm Thanks to all who responded. My thoughts on the assert( newstring != 0 ) ; are as follows (please correct me if I have an incorrect understanding) :-). The assert is used during testing and debugging to verify that memory is being allocated appropriately for the requested data type. It gets taken out at compile time with a #define NDEBUG which causes the assertions to be ignored. Am I incorrect here? BTW, I knew it was simple, I used the isalpha as below. int StrPass::Passed(char *passed) { newstring = new char[ sizeof(passed + 1 )] ; assert( newstring != 0 ) ; if(strlen(passed) >= 5 && strlen(passed) <= 8 ) if( isalpha(passed[0] )) { strcpy(newstring, passed) ; return 0 ; } else return -1 ; } "Wayne A. King" wrote in message news:3fc27fce.130505809@newsgroups.borland.com... > On Mon, 24 Nov 2003 21:31:00 +0100, maeder@glue.ch (Thomas Maeder [TeamB]) > wrote: > > >> newstring = new char[ sizeof(passedstring + 1 )] ; > >> assert( newstring != 0 ) ; > > > >This test is moot. This new expression will *never* evaluate to 0. If the > >allocation request can't be served, the new expression causes an exception > >of type std::bad_alloc to be thrown. > > That depends on the compiler being used. For many/most/all compilers > which are topical in this particular newsgroup, there is no std::bad_alloc > exception. > > > -- > Wayne A. King > (ba994@torfree.net, wayne.king@ablelink.org, > waking@idirect.com, Wayne_A_King@compuserve.com) .