home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!gatech!asuvax!ncar!noao!amethyst!organpipe.uug.arizona.edu!news
- From: dave@cs.arizona.edu (Dave Schaumann)
- Newsgroups: comp.lang.c
- Subject: Re: Where to include
- Message-ID: <1993Jan8.043525.18600@organpipe.uug.arizona.edu>
- Date: 8 Jan 93 04:35:25 GMT
- References: <C0ID0z.504@ulowell.ulowell.edu>
- Sender: news@organpipe.uug.arizona.edu
- Reply-To: dave@cs.arizona.edu (Dave Schaumann)
- Organization: University of Arizona
- Lines: 39
- In-Reply-To: vpham@cs.ulowell.edu (vinh)
-
- In article <C0ID0z.504@ulowell.ulowell.edu>, vpham@cs (vinh) writes:
- [format changed to save lines]
-
- >fun() { /* ... */ }
- >
- >#include <stdio.h>
- >
- >fun2()
- >
- >{ printf("test..."); }
- >
- >we argued at work about where to put stdio.h
-
- Put it at the top of the file. Except for comments, #include's *always*
- appear at the head of the file in my programs, and in virtually all the
- other source I've ever looked at.
-
- Besides being common practice, you should consider that programs are not
- cast in stone. fun() may not need anything from <stdio.h> now, but what
- about later? What if you add a new function that you want to put above
- fun(), but needs something from <stdio.h>? Recall that NULL is defined
- in <stdio.h>, so you don't necessarily need to use an I/O routine to run
- into problems.
-
- >my co-fellow worker thinks it's ugly ; what do you think?
-
- It's not so much ugly (IMHO) as it is a maintainence problem waiting to
- happen. I say put it at the top and leave it there. It doesn't cost
- you anything to do it, and avoids the problems I mentioned above.
-
- >what does the standard say? what does K&R say?
-
- This is strictly a stylistic issue. I haven't seen the standard, but
- I expect it doesn't say anything about it. I wouldn't be surprised if
- K&R doesn't say anything about it either (except by way of example).
-
- --
- Essentia non sunt multiplicanda praeter necessitatum -- William of Ockham
- (Fact need not be multiplied beyond necessity)
-