home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / c / 11652 < prev    next >
Encoding:
Text File  |  1992-07-27  |  2.0 KB  |  64 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!uunet.ca!geac!zooid!ross
  3. From: Ross Ridge <ross@zooid.guild.org>
  4. Subject: Re: HIgher problems at hand. HELP!
  5. Organization: ZOOiD BBS
  6. Date: Mon, 27 Jul 1992 21:23:11 GMT
  7. Message-ID: <1992Jul27.212311.28125@zooid.guild.org>
  8. References: <Brv6oD.Dq5@usenet.ucs.indiana.edu> <1992Jul25.142216.5636@druid.uucp> <9220806.7841@mulga.cs.mu.OZ.AU>
  9. Lines: 53
  10.  
  11. fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
  12. >darcy@druid.uucp (D'Arcy J.M. Cain) writes:
  13. >>/*
  14. >> * strstr - find first occurrence of wanted in s
  15. >> *
  16. >> * based on code by Henry Spencer
  17. >> * modified for ANSI by D'Arcy J.M. Cain
  18. >> */
  19. >>
  20. >>/* The following define required for full checking.  The problem is that */
  21. >>/* the function has to ultimately assign a const char * to the return */
  22. >>/* value which has to be char *.  The answer is to drop the use of */
  23. >>/* const in this module and trust the code to do the right thing */
  24. >>#define        const
  25. >
  26. >Yuck!
  27. >Do *not* #define keywords unless you have absolutely no alternative.
  28. >
  29. >>#include    <string.h>
  30. >
  31. >Now what happens if string.h happens to contain
  32. >    const CHAR_BIT = 8;
  33. >or some such?
  34.  
  35. Include files are very unlikely to contain external definitions like this.
  36. Remeber in C there is world of difference between "#define CHAR_BIT 8"
  37. and "/*static*/ const /*int*/ CHAR_BIT = 8;".  But who knows what's 
  38. in <string.h> so it would be better if the "#define const" was placed
  39. after the "#include <string.h>". 
  40.  
  41. >>char    *strstr(const char *s, const char *wanted)
  42. >
  43. >This is a *different* prototype to the externally visible one, since
  44. >this one doesn't include "const".
  45.  
  46. What externally visable one? 
  47.  
  48. >>    return(s);
  49. >
  50. >The solution to the const problem is just to put a cast in the final return
  51. >statement:
  52. >    return (const char *) s;
  53.  
  54. You mean "return (char *) s;".  This ia probably the better over all
  55. solution, but simply not using const will work to.  
  56.  
  57.                             Ross Ridge
  58.  
  59. -- 
  60. Ross Ridge - The Great HTMU                         l/     //
  61.                                     [OO][oo]
  62. ross@zooid.guild.org                            /()\/()/
  63. uunet.ca!zooid!ross                             db     //
  64.