home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / gs403osk.tgz / gs403osk.tar / c_style.txt < prev    next >
Text File  |  1996-09-22  |  5KB  |  163 lines

  1.    Copyright (C) 1996 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17.  
  18. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  19.  
  20. This file, c-style.txt, describes Aladdin's C coding guidelines.
  21.  
  22. For an overview of Ghostscript and a list of the documentation files, see
  23. README.
  24.  
  25. Generalities
  26. ============
  27.  
  28. All the rules below are meant to produce code that is easy to read.  If you
  29. find a rule getting in your way or producing ugly-looking results once in a
  30. while, it's OK to break it.
  31.  
  32. Indentation
  33. -----------
  34.  
  35. Tab stops are set every 8 columns.
  36.  
  37. File layout
  38. -----------
  39.  
  40. Every code file should start with comments containing a copyright notice,
  41. the name of the file, and a half-to-one-line summary of what the file
  42. contains.
  43.  
  44. C code
  45. ======
  46.  
  47. Indentation
  48. -----------
  49.  
  50. Put the first indentation point at the first tab stop.  Then proceed as
  51. follows:
  52.  
  53.     { ... in-line compound statement ...
  54.     }
  55.     ... construct requiring subordinate code ...
  56.       ... subordinate simple statement ...
  57.     ... construct requiring subordinate code ...
  58.       { ... subordinate code ...
  59.       }
  60.  
  61. Or you can do this if you prefer:
  62.  
  63.     {
  64.       ... in-line compound statement ...
  65.     }
  66.     ... construct requiring subordinate code ...
  67.       ... subordinate simple statement ...
  68.     ... construct requiring subordinate code ...
  69.       {
  70.         ... subordinate code ...
  71.       }
  72.  
  73. But not this:
  74.  
  75.     if ... {
  76.       ... subordinate code ...
  77.     } else {
  78.       ... subordinate code ...
  79.     }
  80.  
  81. Spaces
  82. ------
  83.  
  84. Do put a space:
  85.     - after every comma and semicolon, unless it ends a line;
  86.     - around every binary operator, although you can omit the spaces
  87.     around the innermost operator in a nested expression if you like;
  88.     - on both sides of the the parentheses of an if, for, or while.
  89.  
  90. Don't put a space:
  91.     - at the end of a line;
  92.     - before a comma or semicolon;
  93.     - after unary prefix operators;
  94.     - before the parenthesis of a macro or procedure call.
  95.  
  96. Types
  97. -----
  98.  
  99. Use 'private' instead of 'static' for constructs (procedures and variables)
  100. declared at the outermost scope.  This allows making such constructs either
  101. visible or invisible to profilers with a single changed #define.
  102.  
  103. Use const wherever possible and appropriate.
  104.  
  105. Avoid global variables (non-const data) like the plague.  Avoid global const
  106. data, but don't knock yourself out over it.
  107.  
  108. If you find yourself wanting to use void *, try to find an alternative using
  109. unions or (in the case of super- and subclasses) casts.
  110.  
  111. Use anonymous structures as little as possible.  Declare structure types
  112. like this (the _t on the type name is preferable but not required):
  113.  
  114.     typedef struct xxx_yyy_s {
  115.       ... members ...
  116.     } xxx_yyy_t;
  117.  
  118. Names
  119. -----
  120.  
  121. Use fully spelled-out English words in names rather than contractions.  This
  122. is most important for procedure and macro names, global variables and
  123. constants, #defined and enum values, structure and other typedef names, and
  124. structure member names, and for argument and variable names which have
  125. uninformative types like int.  It's not very important for arguments or
  126. local variables of distinctive types, or for local index or count variables.
  127.  
  128. Procedures, variables, and structures visible outside a single .c file
  129. should generally have a prefix that indicates what subsystem they belong to
  130. (in the case of Ghostscript, gs_ or gx_).  This rule isn't followed very
  131. consistently.
  132.  
  133. Commenting
  134. ----------
  135.  
  136. The most important descriptive comments are
  137.  
  138. Other
  139. -----
  140.  
  141. Format procedures as follows:
  142.  
  143. scope return_type
  144. proc_name(type1 arg1, type2 arg2, type3 arg3, type4 verylongargument4,
  145.   type5 argument5)
  146. {   ... body ...
  147. }
  148.  
  149. Leave a blank line after the declarations of local variables in a procedure
  150. or compound statement, unless there's only 1 variable and the scope is less
  151. than 10 lines or so.
  152.  
  153. PostScript code
  154. ===============
  155.  
  156. Put indentation points every 3 spaces.
  157.  
  158. Format procedure definitions like this:
  159.  
  160. /procname       % <arg1> <arg2> procname <result1> <result2>
  161.  { ...code...
  162.  } bind def
  163.