Newsgroups: comp.lang.c Path: utzoo!utgpu!watserv1!watdragon!trillium.waterloo.edu!amewalduck From: amewalduck@trillium.waterloo.edu (Andrew Walduck) Subject: Re: A question on C programming style Message-ID: <1991Apr13.001142.11468@watdragon.waterloo.edu> Sender: news@watdragon.waterloo.edu (News Owner) Organization: University of Waterloo References: <1991Apr12.103621.8907@umiami.ir.miami.edu> Date: Sat, 13 Apr 1991 00:11:42 GMT Lines: 49 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). >-------- >foo.h > extern save_data (FILE *fp); > >use.c > #include /* Needed because FILE used in foo.h and has to be > included foo.h. */ > #include "foo.h" > >Style 2: (Nested inclusion). >-------- >foo.h > #include /* We know that this has to be included with this. */ > extern save_data (FILE *fp); > >use.c > #include "foo.h" > > #include /* Is now optional and if included, would not be > included twice provided that the is > set up properly. */ > > >Bimal / devebw9f@miavax.ir.miami.edu Well...to put in my two cents (Canadian $), I've just recently started using the nested form... Disadvantages: 1. Slower compilation due to multiple references to the same file... 2. Must include references to the imbedded includes in the make file dependancy list.... 3. Potential for loops if one file omits having a #ifndef, #endif wrapper around it. Advantages: 1. Data heirarchy is better....but harder to maintain as maintainer must understand where in the tree to insert his new definitions...a clear design document (or graph) showing how the datatypes and objects relate is a plus. 2. Also if you include a file, it comes "ready to use" as its already included whatever definitions you may need. Myself, I'm begining to prefer the nested style. Andrew Walduck