home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / cplus / 15921 < prev    next >
Encoding:
Text File  |  1992-11-08  |  1.6 KB  |  48 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!tessi!eaglet!slipknot!robert
  3. From: robert@slipknot.rain.com (Robert Reed)
  4. Subject: Re: const char *
  5. Message-ID: <BxD5uz.90q@slipknot.rain.com>
  6. Reply-To: robert@slipknot.rain.com.UUCP (Robert Reed)
  7. Organization: Home Animation Ltd.
  8. References: <92311.184452KSADEGH@auvm.american.edu>
  9. Date: Sat, 7 Nov 1992 20:49:46 GMT
  10. Lines: 36
  11.  
  12. In article <92311.184452KSADEGH@auvm.american.edu> Kayvon Z. Sadeghi <KSADEGH@auvm.american.edu> writes:
  13. |I have this subroutine call that says:
  14. |mycall("");
  15. |and then somewhere down in my code I have:
  16. |
  17. | mycall(const char *msg){
  18. |     if(msg=="")
  19. |          dothis();
  20. |     if(msg!="")
  21. |          dothat();
  22. |}
  23. |
  24. |Strange, but my compiler doesthat() instead of dothis().
  25. |I even checked the value of msg and it *IS* equal to "". Is something wrong
  26. |with my C++ compiler or what? or are strings treated differently in here?
  27.  
  28. The problem is obvious.  Your "" is not the same as your "".  Remember that
  29. what you're really defining here is a pointer to a string that contains no
  30. non-NUL characters, but that doesn't mean the pointers have to be the same.
  31. Try something like:
  32.  
  33. const char *Empty = "";
  34.  
  35. mycall(const char *msg) {
  36.     if (msg == Empty)
  37.         dothis();
  38.     else
  39.         dothat();
  40. ________________________________________________________________________________
  41. Robert Reed            Home Animation Ltd.        503-656-8414
  42. robert@slipknot.rain.com    5686 First Court, West Linn, OR 97068
  43.  
  44. Why is it a penny for your thoughts, but you have to put your two cents
  45. in?  Somebody's making a penny.
  46. --Steve Wright
  47. ________________________________________________________________________________
  48.