This project has moved and is read-only. For the latest updates, please go here.

This style guide is different from others you may see, because the focus is centered on readability and understandability.

Download Complete C Language Style Guide by NASA (National Aeronautics and Space Administration)

  • Variable and method/function names that contain multiple characters must not start with an uppercase letter.

    Further, each "word" within a variable name should start with an uppercase letter. For example, importantMessage and campusMonitor are both appropriate variable names.

    • Preferred:

      int maximumStudentSize = 100;
    • Not-Preferred:

      int max = 100;
      int maxsize = 100;
  • Variable names that consist of a single character may be uppercase.

    In general, even single-character variable names should be lowercase. However, in some situations, mathematical notation uses uppercase letters. In such situations, uppercase variable names may be used. For example, matrices are often written using uppercase letters. So, an expression like (b = A*x) would be appropriate.

  • Variable and method/function names must be descriptive.

    Variable names like aaa are not appropriate. Index variables and counters can, however, have names like i and j.

    • Preferred:

      int getSumOfTwoNumber(int number1, int number2);
      void printSumOfTwoNumber(int number1, int number2);

      Or you can use as

      int getSumOfTwoNumber(int num1, int num2);
      void printSumOfTwoNumber(int num1, int num2);
    • Not-Preferred:

      int sum(int a, int b);
  • User-defined constants must be entirely in uppercase.
    • Preferred: 
      #define MAXIMUM_STUDENT_SIZE 100;
      const int SIZE 32;
    • Not-Preferred:

      #define MAXIMUMSTUDENTSIZE 100;
      #define MaximumStudentSize 100;
      #define max 100;
      const int size 32;
  • All variables must be declared at the top of the relevant function (with one exception).

    The only exception to this rule is index variables in loops, which may be declared locally.

  • All variables must be declared alphabetically by their type.

    For example, variables of type double should be declared before variables of type int which should, in turn, be declared before variables of type Node.

  • Block comments must start with/* and end with */.
  • Comments in the body of a class should use // rather than /* ... */.

    This isn't a requirement but it will make your life easier since you can't nest comments inside of /* ... */. There is nothing more annoying then trying to "comment out" a section of code while you are debugging and being unable to because it contains block comments.

  • Use indentation and use it consistently.

    No particular indentation scheme is required but you must indent your code in a meaningful and consistent way.

  • Every file must begin with an appropriate comment block.

    It must contain, at a minimum, the name of the file, its purpose, its author, the author's affiliation, and the date it was completed. It must also attest to your compliance with the JMU Honor Code. For example:

    	  * vectormath
    	  * Purpose:   This file contains functions for
              *            performing vector arithmetic.
    	  * Author:    Prof. David Bernstein, James Madison University
    	  * Version:   15 January 1999
    	  * This work complies with the JMU Honor Code.
  • Every function must begin with an appropriate comment block.

    It must contain, at a minimum, the name of the method/function, its arguments (if any), side effects (if any), and what is returned (if anything).

    	  * innerproduct
    	  * Purpose:      Calculate the inner product of two vectors.
    	  * Arguments:    a  One vector of doubles
    	  *               b  The other  vector of doubles
    	  * Side Effects: None
    	  * Returns:      The inner (or dot) product
  • Download Complete C Language Style Guide by NASA (National Aeronautics and Space Administration)

Last edited Sep 6, 2016 at 7:26 AM by vineetchoudhary, version 4