C Style Examples
by P.N. Hilfinger
/* TITLES GO HERE */ /* Comments on variables may go here */ int x; /* or here */ /* Format 1: Comments describing a function that go before it may be */ /* formatted like this. This same format works for variables and general */ /* commentary about an entire program or section of a program. */ /* Format 2: Here is another possible format for extended comments at the front of a source file or before function or variable declarations. */ /* ** Format 3: Here is still another possible format. Some find that comments ** stand out better in this format than in formats 1 or 2. ** Also it is possible to access all the comments via the grep command; ** format 1 allows this too, while format 2 doesn't. */ int F (double a[ ], double b[ ], double c[ ], int n) /* Comments describing a function that go after its header */ /* are indented like this. */ { if (n < 0) { fprintf (stderr, "Erroneous input to F: %d.\n", n); exit (1); } else if (n == 0) { /* note that single statements */ return 0; /* should be bracketed too for safety */ } else { int i; for (i=0; i<n; i++) { /* code is indented here */ } } switch (...) { case 1: x = n; break; case 2: { int local_variable; ... } default: ... } }