home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!tessi!eaglet!slipknot!robert
- From: robert@slipknot.rain.com (Robert Reed)
- Subject: Re: const char *
- Message-ID: <BxD5uz.90q@slipknot.rain.com>
- Reply-To: robert@slipknot.rain.com.UUCP (Robert Reed)
- Organization: Home Animation Ltd.
- References: <92311.184452KSADEGH@auvm.american.edu>
- Date: Sat, 7 Nov 1992 20:49:46 GMT
- Lines: 36
-
- In article <92311.184452KSADEGH@auvm.american.edu> Kayvon Z. Sadeghi <KSADEGH@auvm.american.edu> writes:
- |I have this subroutine call that says:
- |mycall("");
- |and then somewhere down in my code I have:
- |
- | mycall(const char *msg){
- | if(msg=="")
- | dothis();
- | if(msg!="")
- | dothat();
- |}
- |
- |Strange, but my compiler doesthat() instead of dothis().
- |I even checked the value of msg and it *IS* equal to "". Is something wrong
- |with my C++ compiler or what? or are strings treated differently in here?
-
- The problem is obvious. Your "" is not the same as your "". Remember that
- what you're really defining here is a pointer to a string that contains no
- non-NUL characters, but that doesn't mean the pointers have to be the same.
- Try something like:
-
- const char *Empty = "";
-
- mycall(const char *msg) {
- if (msg == Empty)
- dothis();
- else
- dothat();
- ________________________________________________________________________________
- Robert Reed Home Animation Ltd. 503-656-8414
- robert@slipknot.rain.com 5686 First Court, West Linn, OR 97068
-
- Why is it a penny for your thoughts, but you have to put your two cents
- in? Somebody's making a penny.
- --Steve Wright
- ________________________________________________________________________________
-