home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / c / 19400 < prev    next >
Encoding:
Internet Message Format  |  1993-01-08  |  1.9 KB

  1. Path: sparky!uunet!gatech!asuvax!ncar!noao!amethyst!organpipe.uug.arizona.edu!news
  2. From: dave@cs.arizona.edu (Dave Schaumann)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Where to include
  5. Message-ID: <1993Jan8.043525.18600@organpipe.uug.arizona.edu>
  6. Date: 8 Jan 93 04:35:25 GMT
  7. References: <C0ID0z.504@ulowell.ulowell.edu>
  8. Sender: news@organpipe.uug.arizona.edu
  9. Reply-To: dave@cs.arizona.edu (Dave Schaumann)
  10. Organization: University of Arizona
  11. Lines: 39
  12. In-Reply-To: vpham@cs.ulowell.edu (vinh)
  13.  
  14. In article <C0ID0z.504@ulowell.ulowell.edu>, vpham@cs (vinh) writes:
  15. [format changed to save lines]
  16.  
  17. >fun() { /* ... */ }
  18. >
  19. >#include <stdio.h>
  20. >
  21. >fun2()
  22. >
  23. >{ printf("test..."); }
  24. >
  25. >we argued at work about where to put stdio.h
  26.  
  27. Put it at the top of the file.  Except for comments, #include's *always*
  28. appear at the head of the file in my programs, and in virtually all the
  29. other source I've ever looked at.
  30.  
  31. Besides being common practice, you should consider that programs are not
  32. cast in stone.  fun() may not need anything from <stdio.h> now, but what
  33. about later?  What if you add a new function that you want to put above
  34. fun(), but needs something from <stdio.h>?  Recall that NULL is defined
  35. in <stdio.h>, so you don't necessarily need to use an I/O routine to run
  36. into problems.
  37.  
  38. >my co-fellow worker thinks it's ugly ; what do you think?
  39.  
  40. It's not so much ugly (IMHO) as it is a maintainence problem waiting to
  41. happen.  I say put it at the top and leave it there.  It doesn't cost
  42. you anything to do it, and avoids the problems I mentioned above.
  43.  
  44. >what does the standard say? what does K&R say?
  45.  
  46. This is strictly a stylistic issue.  I haven't seen the standard, but
  47. I expect it doesn't say anything about it.  I wouldn't be surprised if
  48. K&R doesn't say anything about it either (except by way of example).
  49.  
  50. -- 
  51. Essentia non sunt multiplicanda praeter necessitatum -- William of Ockham
  52. (Fact need not be multiplied beyond necessity)
  53.