Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!newstop!sun!amdcad!dgcad!dg-rtp!snaggle!barnettr From: barnettr@snaggle.rtp.dg.com (Richard Barnette) Newsgroups: comp.lang.c Subject: Re: A question on C programming style Message-ID: <1991Apr13.204916.18198@dg-rtp.dg.com> Date: 13 Apr 91 20:49:16 GMT References: <1991Apr12.103621.8907@umiami.ir.miami.edu> Sender: usenet@dg-rtp.dg.com (Usenet Administration) Organization: Data General Corporation, RTP, NC. Lines: 35 In article <1991Apr12.103621.8907@umiami.ir.miami.edu> devebw9f@miavax.ir.miami.edu writes: >How do the guru's on the net feel about the following two styles? > >Style 1: (No nested includes - user responsible for proper order of includes). I tend not to prefer this style. Forcing the user of header files to be aware of other header dependencies drastically complicates the programming process. Things get further complicated when the dependencies change (and they almost always do). Then some poor joe (probably not the one who wrote the original code) has to find all the places where the header was included, and add more #include's to handle the new dependency. Or else you forget to delete extra #include's when a dependency is dropped. There are some advantages with this style (see below). >Style 2: (Nested inclusion). My preference. Note however that care should be taken not to include a header twice. This can produce warnings and/or errors depending on the kinds of things in the header. It's wise to make all your #include'd headers look something like this: #ifndef foo #define foo /* contents of file "foo.h" */ #endif Unfortunately, some systems don't do something like this with their standard header files. A #include inside your header file may look innocuous enough, but if the header is included by a file with its own #include , disaster may strike. Richard Barnette | Data General Corporation | obligatory (in)famous quote: (919) 248-6225 | RTP, NC 27709 | You wascal wabbit! Commercial Languages | 62 T.W. Alexander Drive | Wandering wizards won't barnettr@dg-rtp.dg.com | win! - /usr/lib/sendmail