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

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!uunet.ca!geac!r-node!druid!darcy
  3. From: darcy@druid.uucp (D'Arcy J.M. Cain)
  4. Subject: Re: HIgher problems at hand. HELP!
  5. Message-ID: <1992Jul28.104059.4725@druid.uucp>
  6. Date: Tue, 28 Jul 1992 10:40:59 GMT
  7. References: <1992Jul25.142216.5636@druid.uucp> <9220806.7841@mulga.cs.mu.OZ.AU> <1992Jul27.212311.28125@zooid.guild.org>
  8. Organization: D'Arcy Cain Consulting
  9. Lines: 31
  10.  
  11. Ross Ridge <ross@zooid.guild.org> writes:
  12. >fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
  13. >>darcy@druid.uucp (D'Arcy J.M. Cain) writes:
  14. >>>#define        const
  15. >>Do *not* #define keywords unless you have absolutely no alternative.
  16. >>>#include    <string.h>
  17. >>Now what happens if string.h happens to contain
  18. >>    const CHAR_BIT = 8;
  19. >>or some such?
  20. >Include files are very unlikely to contain external definitions like this.
  21. >Remeber in C there is world of difference between "#define CHAR_BIT 8"
  22. >and "/*static*/ const /*int*/ CHAR_BIT = 8;".  But who knows what's 
  23. >in <string.h> so it would be better if the "#define const" was placed
  24. >after the "#include <string.h>". 
  25.  
  26. Except that the whole point is to prevent any warnings with full checking
  27. turned on.  Putting the define after the include would cause warnings
  28. when strstr was redefined.  Note that you can't leave it off either since
  29. the function calls both strlen and strncmp.
  30.  
  31. Other than changing the language itself I don't believe there is a "right"
  32. way to code strstr(3).  Anything you do is a kluge.  My kluge simply has
  33. the benefit of not producing warnings.  However you do have to be aware
  34. in case you do have that really strange hardware where this doesn't work.
  35. That's why I put four lines of comment before the define.
  36.  
  37. -- 
  38. D'Arcy J.M. Cain (darcy@druid.com)  |
  39. D'Arcy Cain Consulting              |   There's no government
  40. Toronto, Ontario, Canada            |   like no government!
  41. +1 416 424 2871          DoD#0082   |
  42.