A question on C programming style

Andrew Walduck amewalduck at trillium.waterloo.edu
Sat Apr 13 10:11:42 AEST 1991


In article <1991Apr12.103621.8907 at umiami.ir.miami.edu> devebw9f at 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 <stdio.h>    /* Needed because FILE used in foo.h and has to be
>                           included foo.h. */
>  #include "foo.h"
>
>Style 2: (Nested inclusion).
>--------
>foo.h
>  #include <stdio.h>     /* We know that this has to be included with this. */
>  extern save_data (FILE *fp);
>
>use.c
>  #include "foo.h"
>
>  #include <stdio.h>    /* Is now optional and if included, would not be 
>                           included twice provided that the <stdio.h> is
>                           set up properly. */
>   
>
>Bimal / devebw9f at 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
                    



More information about the Comp.lang.c mailing list