This commit was generated by cvs2svn to compensate for changes in r6453,
[chise/xemacs-chise.git.1] / info / standards.info-1
1 This is Info file ../info/standards.info, produced by Makeinfo version
2 1.68 from the input file standards.texi.
3
4 START-INFO-DIR-ENTRY
5 * Standards: (standards).        GNU coding standards.
6 END-INFO-DIR-ENTRY
7
8    GNU Coding Standards Copyright (C) 1992, 1993, 1994, 1995, 1996 Free
9 Software Foundation, Inc.
10
11    Permission is granted to make and distribute verbatim copies of this
12 manual provided the copyright notice and this permission notice are
13 preserved on all copies.
14
15    Permission is granted to copy and distribute modified versions of
16 this manual under the conditions for verbatim copying, provided that
17 the entire resulting derived work is distributed under the terms of a
18 permission notice identical to this one.
19
20    Permission is granted to copy and distribute translations of this
21 manual into another language, under the above conditions for modified
22 versions, except that this permission notice may be stated in a
23 translation approved by the Free Software Foundation.
24
25 \1f
26 File: standards.info,  Node: Top,  Next: Preface,  Prev: (dir),  Up: (dir)
27
28 Version
29 *******
30
31    Last updated 17 May 1996.
32
33 * Menu:
34
35 * Preface::                     About the GNU Coding Standards
36 * Intellectual Property::       Keeping Free Software Free
37 * Design Advice::               General Program Design
38 * Program Behavior::            Program Behavior for All Programs
39 * Writing C::                   Making The Best Use of C
40 * Documentation::               Documenting Programs
41 * Managing Releases::           The Release Process
42
43 \1f
44 File: standards.info,  Node: Preface,  Next: Intellectual Property,  Prev: Top,  Up: Top
45
46 About the GNU Coding Standards
47 ******************************
48
49    The GNU Coding Standards were written by Richard Stallman and other
50 GNU Project volunteers.  Their purpose is to make the GNU system clean,
51 consistent, and easy to install.  This document can also be read as a
52 guide to writing portable, robust and reliable programs.  It focuses on
53 programs written in C, but many of the rules and principles are useful
54 even if you write in another programming language.  The rules often
55 state reasons for writing in a certain way.
56
57    Corrections or suggestions regarding this document should be sent to
58 `gnu@prep.ai.mit.edu'.  If you make a suggestion, please include a
59 suggested new wording for it; our time is limited.  We prefer a context
60 diff to the `standards.texi' or `make-stds.texi' files, but if you
61 don't have those files, please mail your suggestion anyway.
62
63    This release of the GNU Coding Standards was last updated 17 May
64 1996.
65
66 \1f
67 File: standards.info,  Node: Intellectual Property,  Next: Design Advice,  Prev: Preface,  Up: Top
68
69 Keeping Free Software Free
70 **************************
71
72    This node discusses how you can make sure that GNU software remains
73 unencumbered.
74
75 * Menu:
76
77 * Reading Non-Free Code::       Referring to Proprietary Programs
78 * Contributions::               Accepting Contributions
79
80 \1f
81 File: standards.info,  Node: Reading Non-Free Code,  Next: Contributions,  Up: Intellectual Property
82
83 Referring to Proprietary Programs
84 =================================
85
86    Don't in any circumstances refer to Unix source code for or during
87 your work on GNU!  (Or to any other proprietary programs.)
88
89    If you have a vague recollection of the internals of a Unix program,
90 this does not absolutely mean you can't write an imitation of it, but
91 do try to organize the imitation internally along different lines,
92 because this is likely to make the details of the Unix version
93 irrelevant and dissimilar to your results.
94
95    For example, Unix utilities were generally optimized to minimize
96 memory use; if you go for speed instead, your program will be very
97 different.  You could keep the entire input file in core and scan it
98 there instead of using stdio.  Use a smarter algorithm discovered more
99 recently than the Unix program.  Eliminate use of temporary files.  Do
100 it in one pass instead of two (we did this in the assembler).
101
102    Or, on the contrary, emphasize simplicity instead of speed.  For some
103 applications, the speed of today's computers makes simpler algorithms
104 adequate.
105
106    Or go for generality.  For example, Unix programs often have static
107 tables or fixed-size strings, which make for arbitrary limits; use
108 dynamic allocation instead.  Make sure your program handles NULs and
109 other funny characters in the input files.  Add a programming language
110 for extensibility and write part of the program in that language.
111
112    Or turn some parts of the program into independently usable
113 libraries.  Or use a simple garbage collector instead of tracking
114 precisely when to free memory, or use a new GNU facility such as
115 obstacks.
116
117 \1f
118 File: standards.info,  Node: Contributions,  Prev: Reading Non-Free Code,  Up: Intellectual Property
119
120 Accepting Contributions
121 =======================
122
123    If someone else sends you a piece of code to add to the program you
124 are working on, we need legal papers to use it--the same sort of legal
125 papers we will need to get from you.  *Each* significant contributor to
126 a program must sign some sort of legal papers in order for us to have
127 clear title to the program.  The main author alone is not enough.
128
129    So, before adding in any contributions from other people, tell us so
130 we can arrange to get the papers.  Then wait until we tell you that we
131 have received the signed papers, before you actually use the
132 contribution.
133
134    This applies both before you release the program and afterward.  If
135 you receive diffs to fix a bug, and they make significant changes, we
136 need legal papers for it.
137
138    You don't need papers for changes of a few lines here or there, since
139 they are not significant for copyright purposes.  Also, you don't need
140 papers if all you get from the suggestion is some ideas, not actual code
141 which you use.  For example, if you write a different solution to the
142 problem, you don't need to get papers.
143
144    We know this is frustrating; it's frustrating for us as well.  But if
145 you don't wait, you are going out on a limb--for example, what if the
146 contributor's employer won't sign a disclaimer?  You might have to take
147 that code out again!
148
149    The very worst thing is if you forget to tell us about the other
150 contributor.  We could be very embarrassed in court some day as a
151 result.
152
153 \1f
154 File: standards.info,  Node: Design Advice,  Next: Program Behavior,  Prev: Intellectual Property,  Up: Top
155
156 General Program Design
157 **********************
158
159    This node discusses some of the issues you should take into account
160 when designing your program.
161
162 * Menu:
163
164 * Compatibility::               Compatibility with other implementations
165 * Using Extensions::            Using non-standard features
166 * ANSI C::                      Using ANSI C features
167 * Source Language::             Using languages other than C
168
169 \1f
170 File: standards.info,  Node: Compatibility,  Next: Using Extensions,  Up: Design Advice
171
172 Compatibility with Other Implementations
173 ========================================
174
175    With occasional exceptions, utility programs and libraries for GNU
176 should be upward compatible with those in Berkeley Unix, and upward
177 compatible with ANSI C if ANSI C specifies their behavior, and upward
178 compatible with POSIX if POSIX specifies their behavior.
179
180    When these standards conflict, it is useful to offer compatibility
181 modes for each of them.
182
183    ANSI C and POSIX prohibit many kinds of extensions.  Feel free to
184 make the extensions anyway, and include a `--ansi', `--posix', or
185 `--compatible' option to turn them off.  However, if the extension has
186 a significant chance of breaking any real programs or scripts, then it
187 is not really upward compatible.  Try to redesign its interface.
188
189    Many GNU programs suppress extensions that conflict with POSIX if the
190 environment variable `POSIXLY_CORRECT' is defined (even if it is
191 defined with a null value).  Please make your program recognize this
192 variable if appropriate.
193
194    When a feature is used only by users (not by programs or command
195 files), and it is done poorly in Unix, feel free to replace it
196 completely with something totally different and better.  (For example,
197 `vi' is replaced with Emacs.)  But it is nice to offer a compatible
198 feature as well.  (There is a free `vi' clone, so we offer it.)
199
200    Additional useful features not in Berkeley Unix are welcome.
201 Additional programs with no counterpart in Unix may be useful, but our
202 first priority is usually to duplicate what Unix already has.
203
204 \1f
205 File: standards.info,  Node: Using Extensions,  Next: ANSI C,  Prev: Compatibility,  Up: Design Advice
206
207 Using Non-standard Features
208 ===========================
209
210    Many GNU facilities that already exist support a number of convenient
211 extensions over the comparable Unix facilities.  Whether to use these
212 extensions in implementing your program is a difficult question.
213
214    On the one hand, using the extensions can make a cleaner program.
215 On the other hand, people will not be able to build the program unless
216 the other GNU tools are available.  This might cause the program to
217 work on fewer kinds of machines.
218
219    With some extensions, it might be easy to provide both alternatives.
220 For example, you can define functions with a "keyword" `INLINE' and
221 define that as a macro to expand into either `inline' or nothing,
222 depending on the compiler.
223
224    In general, perhaps it is best not to use the extensions if you can
225 straightforwardly do without them, but to use the extensions if they
226 are a big improvement.
227
228    An exception to this rule are the large, established programs (such
229 as Emacs) which run on a great variety of systems.  Such programs would
230 be broken by use of GNU extensions.
231
232    Another exception is for programs that are used as part of
233 compilation: anything that must be compiled with other compilers in
234 order to bootstrap the GNU compilation facilities.  If these require
235 the GNU compiler, then no one can compile them without having them
236 installed already.  That would be no good.
237
238 \1f
239 File: standards.info,  Node: ANSI C,  Next: Source Language,  Prev: Using Extensions,  Up: Design Advice
240
241 ANSI C and pre-ANSI C
242 =====================
243
244    Do not ever use the "trigraph" feature of ANSI C.
245
246    ANSI C is widespread enough now that it is ok to write new programs
247 that use ANSI C features (and therefore will not work in non-ANSI
248 compilers).  And if a program is already written in ANSI C, there's no
249 need to convert it to support non-ANSI compilers.
250
251    However, it is easy to support non-ANSI compilers in most programs,
252 so you might still consider doing so when you write a program.  Instead
253 of writing function definitions in ANSI prototype form,
254
255      int
256      foo (int x, int y)
257      ...
258
259 write the definition in pre-ANSI style like this,
260
261      int
262      foo (x, y)
263           int x, y;
264      ...
265
266 and use a separate declaration to specify the argument prototype:
267
268      int foo (int, int);
269
270    You need such a declaration anyway, in a header file, to get the
271 benefit of ANSI C prototypes in all the files where the function is
272 called.  And once you have it, you lose nothing by writing the function
273 definition in the pre-ANSI style.
274
275    If you don't know non-ANSI C, there's no need to learn it; just
276 write in ANSI C.
277
278 \1f
279 File: standards.info,  Node: Source Language,  Prev: ANSI C,  Up: Design Advice
280
281 Using Languages Other Than C
282 ============================
283
284    Using a language other than C is like using a non-standard feature:
285 it will cause trouble for users.  Even if GCC supports the other
286 language, users may find it inconvenient to have to install the
287 compiler for that other language in order to build your program.  So
288 please write in C.
289
290    There are three exceptions for this rule:
291
292    * It is okay to use a special language if the same program contains
293      an interpreter for that language.
294
295      For example, if your program links with GUILE, it is ok to write
296      part of the program in Scheme or another language supported by
297      GUILE.
298
299    * It is okay to use another language in a tool specifically intended
300      for use with that language.
301
302      This is okay because the only people who want to build the tool
303      will be those who have installed the other language anyway.
304
305    * If an application is not of extremely widespread interest, then
306      perhaps it's not important if the application is inconvenient to
307      install.
308
309 \1f
310 File: standards.info,  Node: Program Behavior,  Next: Writing C,  Prev: Design Advice,  Up: Top
311
312 Program Behavior for All Programs
313 *********************************
314
315    This node describes how to write robust software. It also describes
316 general standards for error messages, the command line interface, and
317 how libraries should behave.
318
319 * Menu:
320
321 * Semantics::                   Writing robust programs
322 * Libraries::                   Library behavior
323 * Errors::                      Formatting error messages
324 * User Interfaces::             Standards for command line interfaces
325 * Memory Usage::                When and how to care about memory needs
326
327 \1f
328 File: standards.info,  Node: Semantics,  Next: Libraries,  Up: Program Behavior
329
330 Writing Robust Programs
331 =======================
332
333    Avoid arbitrary limits on the length or number of *any* data
334 structure, including file names, lines, files, and symbols, by
335 allocating all data structures dynamically.  In most Unix utilities,
336 "long lines are silently truncated".  This is not acceptable in a GNU
337 utility.
338
339    Utilities reading files should not drop NUL characters, or any other
340 nonprinting characters *including those with codes above 0177*.  The
341 only sensible exceptions would be utilities specifically intended for
342 interface to certain types of printers that can't handle those
343 characters.
344
345    Check every system call for an error return, unless you know you
346 wish to ignore errors.  Include the system error text (from `perror' or
347 equivalent) in *every* error message resulting from a failing system
348 call, as well as the name of the file if any and the name of the
349 utility.  Just "cannot open foo.c" or "stat failed" is not sufficient.
350
351    Check every call to `malloc' or `realloc' to see if it returned
352 zero.  Check `realloc' even if you are making the block smaller; in a
353 system that rounds block sizes to a power of 2, `realloc' may get a
354 different block if you ask for less space.
355
356    In Unix, `realloc' can destroy the storage block if it returns zero.
357 GNU `realloc' does not have this bug: if it fails, the original block
358 is unchanged.  Feel free to assume the bug is fixed.  If you wish to
359 run your program on Unix, and wish to avoid lossage in this case, you
360 can use the GNU `malloc'.
361
362    You must expect `free' to alter the contents of the block that was
363 freed.  Anything you want to fetch from the block, you must fetch before
364 calling `free'.
365
366    If `malloc' fails in a noninteractive program, make that a fatal
367 error.  In an interactive program (one that reads commands from the
368 user), it is better to abort the command and return to the command
369 reader loop.  This allows the user to kill other processes to free up
370 virtual memory, and then try the command again.
371
372    Use `getopt_long' to decode arguments, unless the argument syntax
373 makes this unreasonable.
374
375    When static storage is to be written in during program execution, use
376 explicit C code to initialize it.  Reserve C initialized declarations
377 for data that will not be changed.
378
379    Try to avoid low-level interfaces to obscure Unix data structures
380 (such as file directories, utmp, or the layout of kernel memory), since
381 these are less likely to work compatibly.  If you need to find all the
382 files in a directory, use `readdir' or some other high-level interface.
383 These will be supported compatibly by GNU.
384
385    By default, the GNU system will provide the signal handling
386 functions of BSD and of POSIX.  So GNU software should be written to use
387 these.
388
389    In error checks that detect "impossible" conditions, just abort.
390 There is usually no point in printing any message.  These checks
391 indicate the existence of bugs.  Whoever wants to fix the bugs will have
392 to read the source code and run a debugger.  So explain the problem with
393 comments in the source.  The relevant data will be in variables, which
394 are easy to examine with the debugger, so there is no point moving them
395 elsewhere.
396
397    Do not use a count of errors as the exit status for a program.
398 *That does not work*, because exit status values are limited to 8 bits
399 (0 through 255).  A single run of the program might have 256 errors; if
400 you try to return 256 as the exit status, the parent process will see 0
401 as the status, and it will appear that the program succeeded.
402
403    If you make temporary files, check the `TMPDIR' environment
404 variable; if that variable is defined, use the specified directory
405 instead of `/tmp'.
406
407 \1f
408 File: standards.info,  Node: Libraries,  Next: Errors,  Prev: Semantics,  Up: Program Behavior
409
410 Library Behavior
411 ================
412
413    Try to make library functions reentrant.  If they need to do dynamic
414 storage allocation, at least try to avoid any nonreentrancy aside from
415 that of `malloc' itself.
416
417    Here are certain name conventions for libraries, to avoid name
418 conflicts.
419
420    Choose a name prefix for the library, more than two characters long.
421 All external function and variable names should start with this prefix.
422 In addition, there should only be one of these in any given library
423 member.  This usually means putting each one in a separate source file.
424
425    An exception can be made when two external symbols are always used
426 together, so that no reasonable program could use one without the
427 other; then they can both go in the same file.
428
429    External symbols that are not documented entry points for the user
430 should have names beginning with `_'.  They should also contain the
431 chosen name prefix for the library, to prevent collisions with other
432 libraries.  These can go in the same files with user entry points if
433 you like.
434
435    Static functions and variables can be used as you like and need not
436 fit any naming convention.
437
438 \1f
439 File: standards.info,  Node: Errors,  Next: User Interfaces,  Prev: Libraries,  Up: Program Behavior
440
441 Formatting Error Messages
442 =========================
443
444    Error messages from compilers should look like this:
445
446      SOURCE-FILE-NAME:LINENO: MESSAGE
447
448    Error messages from other noninteractive programs should look like
449 this:
450
451      PROGRAM:SOURCE-FILE-NAME:LINENO: MESSAGE
452
453 when there is an appropriate source file, or like this:
454
455      PROGRAM: MESSAGE
456
457 when there is no relevant source file.
458
459    In an interactive program (one that is reading commands from a
460 terminal), it is better not to include the program name in an error
461 message.  The place to indicate which program is running is in the
462 prompt or with the screen layout.  (When the same program runs with
463 input from a source other than a terminal, it is not interactive and
464 would do best to print error messages using the noninteractive style.)
465
466    The string MESSAGE should not begin with a capital letter when it
467 follows a program name and/or file name.  Also, it should not end with
468 a period.
469
470    Error messages from interactive programs, and other messages such as
471 usage messages, should start with a capital letter.  But they should not
472 end with a period.
473
474 \1f
475 File: standards.info,  Node: User Interfaces,  Next: Memory Usage,  Prev: Errors,  Up: Program Behavior
476
477 Standards for Command Line Interfaces
478 =====================================
479
480    Please don't make the behavior of a utility depend on the name used
481 to invoke it.  It is useful sometimes to make a link to a utility with
482 a different name, and that should not change what it does.
483
484    Instead, use a run time option or a compilation switch or both to
485 select among the alternate behaviors.
486
487    Likewise, please don't make the behavior of the program depend on the
488 type of output device it is used with.  Device independence is an
489 important principle of the system's design; do not compromise it merely
490 to save someone from typing an option now and then.
491
492    If you think one behavior is most useful when the output is to a
493 terminal, and another is most useful when the output is a file or a
494 pipe, then it is usually best to make the default behavior the one that
495 is useful with output to a terminal, and have an option for the other
496 behavior.
497
498    Compatibility requires certain programs to depend on the type of
499 output device.  It would be disastrous if `ls' or `sh' did not do so in
500 the way all users expect.  In some of these cases, we supplement the
501 program with a preferred alternate version that does not depend on the
502 output device type.  For example, we provide a `dir' program much like
503 `ls' except that its default output format is always multi-column
504 format.
505
506    It is a good idea to follow the POSIX guidelines for the
507 command-line options of a program.  The easiest way to do this is to use
508 `getopt' to parse them.  Note that the GNU version of `getopt' will
509 normally permit options anywhere among the arguments unless the special
510 argument `--' is used.  This is not what POSIX specifies; it is a GNU
511 extension.
512
513    Please define long-named options that are equivalent to the
514 single-letter Unix-style options.  We hope to make GNU more user
515 friendly this way.  This is easy to do with the GNU function
516 `getopt_long'.
517
518    One of the advantages of long-named options is that they can be
519 consistent from program to program.  For example, users should be able
520 to expect the "verbose" option of any GNU program which has one, to be
521 spelled precisely `--verbose'.  To achieve this uniformity, look at the
522 table of common long-option names when you choose the option names for
523 your program.  The table appears below.
524
525    If you use names not already in the table, please send
526 `gnu@prep.ai.mit.edu' a list of them, with their meanings, so we can
527 update the table.
528
529    It is usually a good idea for file names given as ordinary arguments
530 to be input files only; any output files would be specified using
531 options (preferably `-o').  Even if you allow an output file name as an
532 ordinary argument for compatibility, try to provide a suitable option
533 as well.  This will lead to more consistency among GNU utilities, so
534 that there are fewer idiosyncracies for users to remember.
535
536    Programs should support an option `--version' which prints the
537 program's version number on standard output and exits successfully, and
538 an option `--help' which prints option usage information on standard
539 output and exits successfully.  These options should inhibit the normal
540 function of the command; they should do nothing except print the
541 requested information.
542
543    Here is the table of long options used by GNU programs.
544
545 `after-date'
546      `-N' in `tar'.
547
548 `all'
549      `-a' in `du', `ls', `nm', `stty', `uname', and `unexpand'.
550
551 `all-text'
552      `-a' in `diff'.
553
554 `almost-all'
555      `-A' in `ls'.
556
557 `append'
558      `-a' in `etags', `tee', `time'; `-r' in `tar'.
559
560 `archive'
561      `-a' in `cp'.
562
563 `archive-name'
564      `-n' in `shar'.
565
566 `arglength'
567      `-l' in `m4'.
568
569 `ascii'
570      `-a' in `diff'.
571
572 `assign'
573      `-v' in `gawk'.
574
575 `assume-new'
576      `-W' in Make.
577
578 `assume-old'
579      `-o' in Make.
580
581 `auto-check'
582      `-a' in `recode'.
583
584 `auto-pager'
585      `-a' in `wdiff'.
586
587 `auto-reference'
588      `-A' in `ptx'.
589
590 `avoid-wraps'
591      `-n' in `wdiff'.
592
593 `backward-search'
594      `-B' in `ctags'.
595
596 `basename'
597      `-f' in `shar'.
598
599 `batch'
600      Used in GDB.
601
602 `baud'
603      Used in GDB.
604
605 `before'
606      `-b' in `tac'.
607
608 `binary'
609      `-b' in `cpio' and `diff'.
610
611 `bits-per-code'
612      `-b' in `shar'.
613
614 `block-size'
615      Used in `cpio' and `tar'.
616
617 `blocks'
618      `-b' in `head' and `tail'.
619
620 `break-file'
621      `-b' in `ptx'.
622
623 `brief'
624      Used in various programs to make output shorter.
625
626 `bytes'
627      `-c' in `head', `split', and `tail'.
628
629 `c++'
630      `-C' in `etags'.
631
632 `catenate'
633      `-A' in `tar'.
634
635 `cd'
636      Used in various programs to specify the directory to use.
637
638 `changes'
639      `-c' in `chgrp' and `chown'.
640
641 `classify'
642      `-F' in `ls'.
643
644 `colons'
645      `-c' in `recode'.
646
647 `command'
648      `-c' in `su'; `-x' in GDB.
649
650 `compare'
651      `-d' in `tar'.
652
653 `compat'
654      Used in `gawk'.
655
656 `compress'
657      `-Z' in `tar' and `shar'.
658
659 `concatenate'
660      `-A' in `tar'.
661
662 `confirmation'
663      `-w' in `tar'.
664
665 `context'
666      Used in `diff'.
667
668 `copyleft'
669      `-W copyleft' in `gawk'.
670
671 `copyright'
672      `-C' in `ptx', `recode', and `wdiff'; `-W copyright' in `gawk'.
673
674 `core'
675      Used in GDB.
676
677 `count'
678      `-q' in `who'.
679
680 `count-links'
681      `-l' in `du'.
682
683 `create'
684      Used in `tar' and `cpio'.
685
686 `cut-mark'
687      `-c' in `shar'.
688
689 `cxref'
690      `-x' in `ctags'.
691
692 `date'
693      `-d' in `touch'.
694
695 `debug'
696      `-d' in Make and `m4'; `-t' in Bison.
697
698 `define'
699      `-D' in `m4'.
700
701 `defines'
702      `-d' in Bison and `ctags'.
703
704 `delete'
705      `-D' in `tar'.
706
707 `dereference'
708      `-L' in `chgrp', `chown', `cpio', `du', `ls', and `tar'.
709
710 `dereference-args'
711      `-D' in `du'.
712
713 `diacritics'
714      `-d' in `recode'.
715
716 `dictionary-order'
717      `-d' in `look'.
718
719 `diff'
720      `-d' in `tar'.
721
722 `digits'
723      `-n' in `csplit'.
724
725 `directory'
726      Specify the directory to use, in various programs.  In `ls', it
727      means to show directories themselves rather than their contents.
728      In `rm' and `ln', it means to not treat links to directories
729      specially.
730
731 `discard-all'
732      `-x' in `strip'.
733
734 `discard-locals'
735      `-X' in `strip'.
736
737 `dry-run'
738      `-n' in Make.
739
740 `ed'
741      `-e' in `diff'.
742
743 `elide-empty-files'
744      `-z' in `csplit'.
745
746 `end-delete'
747      `-x' in `wdiff'.
748
749 `end-insert'
750      `-z' in `wdiff'.
751
752 `entire-new-file'
753      `-N' in `diff'.
754
755 `environment-overrides'
756      `-e' in Make.
757
758 `eof'
759      `-e' in `xargs'.
760
761 `epoch'
762      Used in GDB.
763
764 `error-limit'
765      Used in `makeinfo'.
766
767 `error-output'
768      `-o' in `m4'.
769
770 `escape'
771      `-b' in `ls'.
772
773 `exclude-from'
774      `-X' in `tar'.
775
776 `exec'
777      Used in GDB.
778
779 `exit'
780      `-x' in `xargs'.
781
782 `exit-0'
783      `-e' in `unshar'.
784
785 `expand-tabs'
786      `-t' in `diff'.
787
788 `expression'
789      `-e' in `sed'.
790
791 `extern-only'
792      `-g' in `nm'.
793
794 `extract'
795      `-i' in `cpio'; `-x' in `tar'.
796
797 `faces'
798      `-f' in `finger'.
799
800 `fast'
801      `-f' in `su'.
802
803 `fatal-warnings'
804      `-E' in `m4'.
805
806 `file'
807      `-f' in `info', `gawk', Make, `mt', and `tar'; `-n' in `sed'; `-r'
808      in `touch'.
809
810 `field-separator'
811      `-F' in `gawk'.
812
813 `file-prefix'
814      `-b' in Bison.
815
816 `file-type'
817      `-F' in `ls'.
818
819 `files-from'
820      `-T' in `tar'.
821
822 `fill-column'
823      Used in `makeinfo'.
824
825 `flag-truncation'
826      `-F' in `ptx'.
827
828 `fixed-output-files'
829      `-y' in Bison.
830
831 `follow'
832      `-f' in `tail'.
833
834 `footnote-style'
835      Used in `makeinfo'.
836
837 `force'
838      `-f' in `cp', `ln', `mv', and `rm'.
839
840 `force-prefix'
841      `-F' in `shar'.
842
843 `format'
844      Used in `ls', `time', and `ptx'.
845
846 `freeze-state'
847      `-F' in `m4'.
848
849 `fullname'
850      Used in GDB.
851
852 `gap-size'
853      `-g' in `ptx'.
854
855 `get'
856      `-x' in `tar'.
857
858 `graphic'
859      `-i' in `ul'.
860
861 `graphics'
862      `-g' in `recode'.
863
864 `group'
865      `-g' in `install'.
866
867 `gzip'
868      `-z' in `tar' and `shar'.
869
870 `hashsize'
871      `-H' in `m4'.
872
873 `header'
874      `-h' in `objdump' and `recode'
875
876 `heading'
877      `-H' in `who'.
878
879 `help'
880      Used to ask for brief usage information.
881
882 `here-delimiter'
883      `-d' in `shar'.
884
885 `hide-control-chars'
886      `-q' in `ls'.
887
888 `idle'
889      `-u' in `who'.
890
891 `ifdef'
892      `-D' in `diff'.
893
894 `ignore'
895      `-I' in `ls'; `-x' in `recode'.
896
897 `ignore-all-space'
898      `-w' in `diff'.
899
900 `ignore-backups'
901      `-B' in `ls'.
902
903 `ignore-blank-lines'
904      `-B' in `diff'.
905
906 `ignore-case'
907      `-f' in `look' and `ptx'; `-i' in `diff' and `wdiff'.
908
909 `ignore-errors'
910      `-i' in Make.
911
912 `ignore-file'
913      `-i' in `ptx'.
914
915 `ignore-indentation'
916      `-I' in `etags'.
917
918 `ignore-init-file'
919      `-f' in Oleo.
920
921 `ignore-interrupts'
922      `-i' in `tee'.
923
924 `ignore-matching-lines'
925      `-I' in `diff'.
926
927 `ignore-space-change'
928      `-b' in `diff'.
929
930 `ignore-zeros'
931      `-i' in `tar'.
932
933 `include'
934      `-i' in `etags'; `-I' in `m4'.
935
936 `include-dir'
937      `-I' in Make.
938
939 `incremental'
940      `-G' in `tar'.
941
942 `info'
943      `-i', `-l', and `-m' in Finger.
944
945 `initial'
946      `-i' in `expand'.
947
948 `initial-tab'
949      `-T' in `diff'.
950
951 `inode'
952      `-i' in `ls'.
953
954 `interactive'
955      `-i' in `cp', `ln', `mv', `rm'; `-e' in `m4'; `-p' in `xargs';
956      `-w' in `tar'.
957
958 `intermix-type'
959      `-p' in `shar'.
960
961 `jobs'
962      `-j' in Make.
963
964 `just-print'
965      `-n' in Make.
966
967 `keep-going'
968      `-k' in Make.
969
970 `keep-files'
971      `-k' in `csplit'.
972
973 `kilobytes'
974      `-k' in `du' and `ls'.
975
976 `language'
977      `-l' in `etags'.
978
979 `less-mode'
980      `-l' in `wdiff'.
981
982 `level-for-gzip'
983      `-g' in `shar'.
984
985 `line-bytes'
986      `-C' in `split'.
987
988 `lines'
989      Used in `split', `head', and `tail'.
990
991 `link'
992      `-l' in `cpio'.
993
994 `lint'
995 `lint-old'
996      Used in `gawk'.
997
998 `list'
999      `-t' in `cpio'; `-l' in `recode'.
1000
1001 `list'
1002      `-t' in `tar'.
1003
1004 `literal'
1005      `-N' in `ls'.
1006
1007 `load-average'
1008      `-l' in Make.
1009
1010 `login'
1011      Used in `su'.
1012
1013 `machine'
1014      No listing of which programs already use this; someone should
1015      check to see if any actually do and tell `gnu@prep.ai.mit.edu'.
1016
1017 `macro-name'
1018      `-M' in `ptx'.
1019
1020 `mail'
1021      `-m' in `hello' and `uname'.
1022
1023 `make-directories'
1024      `-d' in `cpio'.
1025
1026 `makefile'
1027      `-f' in Make.
1028
1029 `mapped'
1030      Used in GDB.
1031
1032 `max-args'
1033      `-n' in `xargs'.
1034
1035 `max-chars'
1036      `-n' in `xargs'.
1037
1038 `max-lines'
1039      `-l' in `xargs'.
1040
1041 `max-load'
1042      `-l' in Make.
1043
1044 `max-procs'
1045      `-P' in `xargs'.
1046
1047 `mesg'
1048      `-T' in `who'.
1049
1050 `message'
1051      `-T' in `who'.
1052
1053 `minimal'
1054      `-d' in `diff'.
1055
1056 `mixed-uuencode'
1057      `-M' in `shar'.
1058
1059 `mode'
1060      `-m' in `install', `mkdir', and `mkfifo'.
1061
1062 `modification-time'
1063      `-m' in `tar'.
1064
1065 `multi-volume'
1066      `-M' in `tar'.
1067
1068 `name-prefix'
1069      `-a' in Bison.
1070
1071 `nesting-limit'
1072      `-L' in `m4'.
1073
1074 `net-headers'
1075      `-a' in `shar'.
1076
1077 `new-file'
1078      `-W' in Make.
1079
1080 `no-builtin-rules'
1081      `-r' in Make.
1082
1083 `no-character-count'
1084      `-w' in `shar'.
1085
1086 `no-check-existing'
1087      `-x' in `shar'.
1088
1089 `no-common'
1090      `-3' in `wdiff'.
1091
1092 `no-create'
1093      `-c' in `touch'.
1094
1095 `no-defines'
1096      `-D' in `etags'.
1097
1098 `no-deleted'
1099      `-1' in `wdiff'.
1100
1101 `no-dereference'
1102      `-d' in `cp'.
1103
1104 `no-inserted'
1105      `-2' in `wdiff'.
1106
1107 `no-keep-going'
1108      `-S' in Make.
1109
1110 `no-lines'
1111      `-l' in Bison.
1112
1113 `no-piping'
1114      `-P' in `shar'.
1115
1116 `no-prof'
1117      `-e' in `gprof'.
1118
1119 `no-regex'
1120      `-R' in `etags'.
1121
1122 `no-sort'
1123      `-p' in `nm'.
1124
1125 `no-split'
1126      Used in `makeinfo'.
1127
1128 `no-static'
1129      `-a' in `gprof'.
1130
1131 `no-time'
1132      `-E' in `gprof'.
1133
1134 `no-timestamp'
1135      `-m' in `shar'.
1136
1137 `no-validate'
1138      Used in `makeinfo'.
1139
1140 `no-warn'
1141      Used in various programs to inhibit warnings.
1142
1143 `node'
1144      `-n' in `info'.
1145
1146 `nodename'
1147      `-n' in `uname'.
1148
1149 `nonmatching'
1150      `-f' in `cpio'.
1151
1152 `nstuff'
1153      `-n' in `objdump'.
1154
1155 `null'
1156      `-0' in `xargs'.
1157
1158 `number'
1159      `-n' in `cat'.
1160
1161 `number-nonblank'
1162      `-b' in `cat'.
1163
1164 `numeric-sort'
1165      `-n' in `nm'.
1166
1167 `numeric-uid-gid'
1168      `-n' in `cpio' and `ls'.
1169
1170 `nx'
1171      Used in GDB.
1172
1173 `old-archive'
1174      `-o' in `tar'.
1175
1176 `old-file'
1177      `-o' in Make.
1178
1179 `one-file-system'
1180      `-l' in `tar', `cp', and `du'.
1181
1182 `only-file'
1183      `-o' in `ptx'.
1184
1185 `only-prof'
1186      `-f' in `gprof'.
1187
1188 `only-time'
1189      `-F' in `gprof'.
1190
1191 `output'
1192      In various programs, specify the output file name.
1193
1194 `output-prefix'
1195      `-o' in `shar'.
1196
1197 `override'
1198      `-o' in `rm'.
1199
1200 `overwrite'
1201      `-c' in `unshar'.
1202
1203 `owner'
1204      `-o' in `install'.
1205
1206 `paginate'
1207      `-l' in `diff'.
1208
1209 `paragraph-indent'
1210      Used in `makeinfo'.
1211
1212 `parents'
1213      `-p' in `mkdir' and `rmdir'.
1214
1215 `pass-all'
1216      `-p' in `ul'.
1217
1218 `pass-through'
1219      `-p' in `cpio'.
1220
1221 `port'
1222      `-P' in `finger'.
1223
1224 `portability'
1225      `-c' in `cpio' and `tar'.
1226
1227 `posix'
1228      Used in `gawk'.
1229
1230 `prefix-builtins'
1231      `-P' in `m4'.
1232
1233 `prefix'
1234      `-f' in `csplit'.
1235
1236 `preserve'
1237      Used in `tar' and `cp'.
1238
1239 `preserve-environment'
1240      `-p' in `su'.
1241
1242 `preserve-modification-time'
1243      `-m' in `cpio'.
1244
1245 `preserve-order'
1246      `-s' in `tar'.
1247
1248 `preserve-permissions'
1249      `-p' in `tar'.
1250
1251 `print'
1252      `-l' in `diff'.
1253
1254 `print-chars'
1255      `-L' in `cmp'.
1256
1257 `print-data-base'
1258      `-p' in Make.
1259
1260 `print-directory'
1261      `-w' in Make.
1262
1263 `print-file-name'
1264      `-o' in `nm'.
1265
1266 `print-symdefs'
1267      `-s' in `nm'.
1268
1269 `printer'
1270      `-p' in `wdiff'.
1271
1272 `prompt'
1273      `-p' in `ed'.
1274
1275 `query-user'
1276      `-X' in `shar'.
1277
1278 `question'
1279      `-q' in Make.
1280
1281 `quiet'
1282      Used in many programs to inhibit the usual output.  *Please note:*
1283      every program accepting `--quiet' should accept `--silent' as a
1284      synonym.
1285
1286 `quiet-unshar'
1287      `-Q' in `shar'
1288
1289 `quote-name'
1290      `-Q' in `ls'.
1291
1292 `rcs'
1293      `-n' in `diff'.
1294
1295 `re-interval'
1296      Used in `gawk'.
1297
1298 `read-full-blocks'
1299      `-B' in `tar'.
1300
1301 `readnow'
1302      Used in GDB.
1303
1304 `recon'
1305      `-n' in Make.
1306
1307 `record-number'
1308      `-R' in `tar'.
1309
1310 `recursive'
1311      Used in `chgrp', `chown', `cp', `ls', `diff', and `rm'.
1312
1313 `reference-limit'
1314      Used in `makeinfo'.
1315
1316 `references'
1317      `-r' in `ptx'.
1318
1319 `regex'
1320      `-r' in `tac' and `etags'.
1321
1322 `release'
1323      `-r' in `uname'.
1324
1325 `reload-state'
1326      `-R' in `m4'.
1327
1328 `relocation'
1329      `-r' in `objdump'.
1330
1331 `rename'
1332      `-r' in `cpio'.
1333
1334 `replace'
1335      `-i' in `xargs'.
1336
1337 `report-identical-files'
1338      `-s' in `diff'.
1339
1340 `reset-access-time'
1341      `-a' in `cpio'.
1342
1343 `reverse'
1344      `-r' in `ls' and `nm'.
1345
1346 `reversed-ed'
1347      `-f' in `diff'.
1348
1349 `right-side-defs'
1350      `-R' in `ptx'.
1351
1352 `same-order'
1353      `-s' in `tar'.
1354
1355 `same-permissions'
1356      `-p' in `tar'.
1357
1358 `save'
1359      `-g' in `stty'.
1360
1361 `se'
1362      Used in GDB.
1363
1364 `sentence-regexp'
1365      `-S' in `ptx'.
1366
1367 `separate-dirs'
1368      `-S' in `du'.
1369
1370 `separator'
1371      `-s' in `tac'.
1372
1373 `sequence'
1374      Used by `recode' to chose files or pipes for sequencing passes.
1375
1376 `shell'
1377      `-s' in `su'.
1378
1379 `show-all'
1380      `-A' in `cat'.
1381
1382 `show-c-function'
1383      `-p' in `diff'.
1384
1385 `show-ends'
1386      `-E' in `cat'.
1387
1388 `show-function-line'
1389      `-F' in `diff'.
1390
1391 `show-tabs'
1392      `-T' in `cat'.
1393
1394 `silent'
1395      Used in many programs to inhibit the usual output.  *Please note:*
1396      every program accepting `--silent' should accept `--quiet' as a
1397      synonym.
1398
1399 `size'
1400      `-s' in `ls'.
1401
1402 `sort'
1403      Used in `ls'.
1404
1405 `source'
1406      `-W source' in `gawk'.
1407
1408 `sparse'
1409      `-S' in `tar'.
1410
1411 `speed-large-files'
1412      `-H' in `diff'.
1413
1414 `split-at'
1415      `-E' in `unshar'.
1416
1417 `split-size-limit'
1418      `-L' in `shar'.
1419
1420 `squeeze-blank'
1421      `-s' in `cat'.
1422
1423 `start-delete'
1424      `-w' in `wdiff'.
1425
1426 `start-insert'
1427      `-y' in `wdiff'.
1428
1429 `starting-file'
1430      Used in `tar' and `diff' to specify which file within a directory
1431      to start processing with.
1432
1433 `statistics'
1434      `-s' in `wdiff'.
1435
1436 `stdin-file-list'
1437      `-S' in `shar'.
1438
1439 `stop'
1440      `-S' in Make.
1441
1442 `strict'
1443      `-s' in `recode'.
1444
1445 `strip'
1446      `-s' in `install'.
1447
1448 `strip-all'
1449      `-s' in `strip'.
1450
1451 `strip-debug'
1452      `-S' in `strip'.
1453
1454 `submitter'
1455      `-s' in `shar'.
1456
1457 `suffix'
1458      `-S' in `cp', `ln', `mv'.
1459
1460 `suffix-format'
1461      `-b' in `csplit'.
1462
1463 `sum'
1464      `-s' in `gprof'.
1465
1466 `summarize'
1467      `-s' in `du'.
1468
1469 `symbolic'
1470      `-s' in `ln'.
1471
1472 `symbols'
1473      Used in GDB and `objdump'.
1474
1475 `synclines'
1476      `-s' in `m4'.
1477
1478 `sysname'
1479      `-s' in `uname'.
1480
1481 `tabs'
1482      `-t' in `expand' and `unexpand'.
1483
1484 `tabsize'
1485      `-T' in `ls'.
1486
1487 `terminal'
1488      `-T' in `tput' and `ul'.  `-t' in `wdiff'.
1489
1490 `text'
1491      `-a' in `diff'.
1492
1493 `text-files'
1494      `-T' in `shar'.
1495
1496 `time'
1497      Used in `ls' and `touch'.
1498
1499 `to-stdout'
1500      `-O' in `tar'.
1501
1502 `total'
1503      `-c' in `du'.
1504
1505 `touch'
1506      `-t' in Make, `ranlib', and `recode'.
1507
1508 `trace'
1509      `-t' in `m4'.
1510
1511 `traditional'
1512      `-t' in `hello'; `-W traditional' in `gawk'; `-G' in `ed', `m4',
1513      and `ptx'.
1514
1515 `tty'
1516      Used in GDB.
1517
1518 `typedefs'
1519      `-t' in `ctags'.
1520
1521 `typedefs-and-c++'
1522      `-T' in `ctags'.
1523
1524 `typeset-mode'
1525      `-t' in `ptx'.
1526
1527 `uncompress'
1528      `-z' in `tar'.
1529
1530 `unconditional'
1531      `-u' in `cpio'.
1532
1533 `undefine'
1534      `-U' in `m4'.
1535
1536 `undefined-only'
1537      `-u' in `nm'.
1538
1539 `update'
1540      `-u' in `cp', `ctags', `mv', `tar'.
1541
1542 `usage'
1543      Used in `gawk'; same as `--help'.
1544
1545 `uuencode'
1546      `-B' in `shar'.
1547
1548 `vanilla-operation'
1549      `-V' in `shar'.
1550
1551 `verbose'
1552      Print more information about progress.  Many programs support this.
1553
1554 `verify'
1555      `-W' in `tar'.
1556
1557 `version'
1558      Print the version number.
1559
1560 `version-control'
1561      `-V' in `cp', `ln', `mv'.
1562
1563 `vgrind'
1564      `-v' in `ctags'.
1565
1566 `volume'
1567      `-V' in `tar'.
1568
1569 `what-if'
1570      `-W' in Make.
1571
1572 `whole-size-limit'
1573      `-l' in `shar'.
1574
1575 `width'
1576      `-w' in `ls' and `ptx'.
1577
1578 `word-regexp'
1579      `-W' in `ptx'.
1580
1581 `writable'
1582      `-T' in `who'.
1583
1584 `zeros'
1585      `-z' in `gprof'.
1586
1587 \1f
1588 File: standards.info,  Node: Memory Usage,  Prev: User Interfaces,  Up: Program Behavior
1589
1590 Memory Usage
1591 ============
1592
1593    If it typically uses just a few meg of memory, don't bother making
1594 any effort to reduce memory usage.  For example, if it is impractical
1595 for other reasons to operate on files more than a few meg long, it is
1596 reasonable to read entire input files into core to operate on them.
1597
1598    However, for programs such as `cat' or `tail', that can usefully
1599 operate on very large files, it is important to avoid using a technique
1600 that would artificially limit the size of files it can handle.  If a
1601 program works by lines and could be applied to arbitrary user-supplied
1602 input files, it should keep only a line in memory, because this is not
1603 very hard and users will want to be able to operate on input files that
1604 are bigger than will fit in core all at once.
1605
1606    If your program creates complicated data structures, just make them
1607 in core and give a fatal error if `malloc' returns zero.
1608
1609 \1f
1610 File: standards.info,  Node: Writing C,  Next: Documentation,  Prev: Program Behavior,  Up: Top
1611
1612 Making The Best Use of C
1613 ************************
1614
1615    This node provides advice on how best to use the C language when
1616 writing GNU software.
1617
1618 * Menu:
1619
1620 * Formatting::                  Formatting Your Source Code
1621 * Comments::                    Commenting Your Work
1622 * Syntactic Conventions::       Clean Use of C Constructs
1623 * Names::                       Naming Variables and Functions
1624 * System Portability::          Portability between different operating systems
1625 * CPU Portability::             Supporting the range of CPU types
1626 * System Functions::            Portability and "standard" library functions
1627 * Internationalization::        Techniques for internationalization
1628
1629 \1f
1630 File: standards.info,  Node: Formatting,  Next: Comments,  Up: Writing C
1631
1632 Formatting Your Source Code
1633 ===========================
1634
1635    It is important to put the open-brace that starts the body of a C
1636 function in column zero, and avoid putting any other open-brace or
1637 open-parenthesis or open-bracket in column zero.  Several tools look
1638 for open-braces in column zero to find the beginnings of C functions.
1639 These tools will not work on code not formatted that way.
1640
1641    It is also important for function definitions to start the name of
1642 the function in column zero.  This helps people to search for function
1643 definitions, and may also help certain tools recognize them.  Thus, the
1644 proper format is this:
1645
1646      static char *
1647      concat (s1, s2)        /* Name starts in column zero here */
1648           char *s1, *s2;
1649      {                     /* Open brace in column zero here */
1650        ...
1651      }
1652
1653 or, if you want to use ANSI C, format the definition like this:
1654
1655      static char *
1656      concat (char *s1, char *s2)
1657      {
1658        ...
1659      }
1660
1661    In ANSI C, if the arguments don't fit nicely on one line, split it
1662 like this:
1663
1664      int
1665      lots_of_args (int an_integer, long a_long, short a_short,
1666                    double a_double, float a_float)
1667      ...
1668
1669    For the body of the function, we prefer code formatted like this:
1670
1671      if (x < foo (y, z))
1672        haha = bar[4] + 5;
1673      else
1674        {
1675          while (z)
1676            {
1677              haha += foo (z, z);
1678              z--;
1679            }
1680          return ++x + bar ();
1681        }
1682
1683    We find it easier to read a program when it has spaces before the
1684 open-parentheses and after the commas.  Especially after the commas.
1685
1686    When you split an expression into multiple lines, split it before an
1687 operator, not after one.  Here is the right way:
1688
1689      if (foo_this_is_long && bar > win (x, y, z)
1690          && remaining_condition)
1691
1692    Try to avoid having two operators of different precedence at the same
1693 level of indentation.  For example, don't write this:
1694
1695      mode = (inmode[j] == VOIDmode
1696              || GET_MODE_SIZE (outmode[j]) > GET_MODE_SIZE (inmode[j])
1697              ? outmode[j] : inmode[j]);
1698
1699    Instead, use extra parentheses so that the indentation shows the
1700 nesting:
1701
1702      mode = ((inmode[j] == VOIDmode
1703               || (GET_MODE_SIZE (outmode[j]) > GET_MODE_SIZE (inmode[j])))
1704              ? outmode[j] : inmode[j]);
1705
1706    Insert extra parentheses so that Emacs will indent the code properly.
1707 For example, the following indentation looks nice if you do it by hand,
1708 but Emacs would mess it up:
1709
1710      v = rup->ru_utime.tv_sec*1000 + rup->ru_utime.tv_usec/1000
1711          + rup->ru_stime.tv_sec*1000 + rup->ru_stime.tv_usec/1000;
1712
1713    But adding a set of parentheses solves the problem:
1714
1715      v = (rup->ru_utime.tv_sec*1000 + rup->ru_utime.tv_usec/1000
1716           + rup->ru_stime.tv_sec*1000 + rup->ru_stime.tv_usec/1000);
1717
1718    Format do-while statements like this:
1719
1720      do
1721        {
1722          a = foo (a);
1723        }
1724      while (a > 0);
1725
1726    Please use formfeed characters (control-L) to divide the program into
1727 pages at logical places (but not within a function).  It does not matter
1728 just how long the pages are, since they do not have to fit on a printed
1729 page.  The formfeeds should appear alone on lines by themselves.
1730
1731 \1f
1732 File: standards.info,  Node: Comments,  Next: Syntactic Conventions,  Prev: Formatting,  Up: Writing C
1733
1734 Commenting Your Work
1735 ====================
1736
1737    Every program should start with a comment saying briefly what it is
1738 for.  Example: `fmt - filter for simple filling of text'.
1739
1740    Please put a comment on each function saying what the function does,
1741 what sorts of arguments it gets, and what the possible values of
1742 arguments mean and are used for.  It is not necessary to duplicate in
1743 words the meaning of the C argument declarations, if a C type is being
1744 used in its customary fashion.  If there is anything nonstandard about
1745 its use (such as an argument of type `char *' which is really the
1746 address of the second character of a string, not the first), or any
1747 possible values that would not work the way one would expect (such as,
1748 that strings containing newlines are not guaranteed to work), be sure
1749 to say so.
1750
1751    Also explain the significance of the return value, if there is one.
1752
1753    Please put two spaces after the end of a sentence in your comments,
1754 so that the Emacs sentence commands will work.  Also, please write
1755 complete sentences and capitalize the first word.  If a lower-case
1756 identifier comes at the beginning of a sentence, don't capitalize it!
1757 Changing the spelling makes it a different identifier.  If you don't
1758 like starting a sentence with a lower case letter, write the sentence
1759 differently (e.g., "The identifier lower-case is ...").
1760
1761    The comment on a function is much clearer if you use the argument
1762 names to speak about the argument values.  The variable name itself
1763 should be lower case, but write it in upper case when you are speaking
1764 about the value rather than the variable itself.  Thus, "the inode
1765 number NODE_NUM" rather than "an inode".
1766
1767    There is usually no purpose in restating the name of the function in
1768 the comment before it, because the reader can see that for himself.
1769 There might be an exception when the comment is so long that the
1770 function itself would be off the bottom of the screen.
1771
1772    There should be a comment on each static variable as well, like this:
1773
1774      /* Nonzero means truncate lines in the display;
1775         zero means continue them.  */
1776      int truncate_lines;
1777
1778    Every `#endif' should have a comment, except in the case of short
1779 conditionals (just a few lines) that are not nested.  The comment should
1780 state the condition of the conditional that is ending, *including its
1781 sense*.  `#else' should have a comment describing the condition *and
1782 sense* of the code that follows.  For example:
1783
1784      #ifdef foo
1785        ...
1786      #else /* not foo */
1787        ...
1788      #endif /* not foo */
1789
1790 but, by contrast, write the comments this way for a `#ifndef':
1791
1792      #ifndef foo
1793        ...
1794      #else /* foo */
1795        ...
1796      #endif /* foo */
1797
1798 \1f
1799 File: standards.info,  Node: Syntactic Conventions,  Next: Names,  Prev: Comments,  Up: Writing C
1800
1801 Clean Use of C Constructs
1802 =========================
1803
1804    Please explicitly declare all arguments to functions.  Don't omit
1805 them just because they are `int's.
1806
1807    Declarations of external functions and functions to appear later in
1808 the source file should all go in one place near the beginning of the
1809 file (somewhere before the first function definition in the file), or
1810 else should go in a header file.  Don't put `extern' declarations inside
1811 functions.
1812
1813    It used to be common practice to use the same local variables (with
1814 names like `tem') over and over for different values within one
1815 function.  Instead of doing this, it is better declare a separate local
1816 variable for each distinct purpose, and give it a name which is
1817 meaningful.  This not only makes programs easier to understand, it also
1818 facilitates optimization by good compilers.  You can also move the
1819 declaration of each local variable into the smallest scope that includes
1820 all its uses.  This makes the program even cleaner.
1821
1822    Don't use local variables or parameters that shadow global
1823 identifiers.
1824
1825    Don't declare multiple variables in one declaration that spans lines.
1826 Start a new declaration on each line, instead.  For example, instead of
1827 this:
1828
1829      int    foo,
1830             bar;
1831
1832 write either this:
1833
1834      int foo, bar;
1835
1836 or this:
1837
1838      int foo;
1839      int bar;
1840
1841 (If they are global variables, each should have a comment preceding it
1842 anyway.)
1843
1844    When you have an `if'-`else' statement nested in another `if'
1845 statement, always put braces around the `if'-`else'.  Thus, never write
1846 like this:
1847
1848      if (foo)
1849        if (bar)
1850          win ();
1851        else
1852          lose ();
1853
1854 always like this:
1855
1856      if (foo)
1857        {
1858          if (bar)
1859            win ();
1860          else
1861            lose ();
1862        }
1863
1864    If you have an `if' statement nested inside of an `else' statement,
1865 either write `else if' on one line, like this,
1866
1867      if (foo)
1868        ...
1869      else if (bar)
1870        ...
1871
1872 with its `then'-part indented like the preceding `then'-part, or write
1873 the nested `if' within braces like this:
1874
1875      if (foo)
1876        ...
1877      else
1878        {
1879          if (bar)
1880            ...
1881        }
1882
1883    Don't declare both a structure tag and variables or typedefs in the
1884 same declaration.  Instead, declare the structure tag separately and
1885 then use it to declare the variables or typedefs.
1886
1887    Try to avoid assignments inside `if'-conditions.  For example, don't
1888 write this:
1889
1890      if ((foo = (char *) malloc (sizeof *foo)) == 0)
1891        fatal ("virtual memory exhausted");
1892
1893 instead, write this:
1894
1895      foo = (char *) malloc (sizeof *foo);
1896      if (foo == 0)
1897        fatal ("virtual memory exhausted");
1898
1899    Don't make the program ugly to placate `lint'.  Please don't insert
1900 any casts to `void'.  Zero without a cast is perfectly fine as a null
1901 pointer constant, except when calling a varargs function.
1902
1903 \1f
1904 File: standards.info,  Node: Names,  Next: System Portability,  Prev: Syntactic Conventions,  Up: Writing C
1905
1906 Naming Variables and Functions
1907 ==============================
1908
1909    Please use underscores to separate words in a name, so that the Emacs
1910 word commands can be useful within them.  Stick to lower case; reserve
1911 upper case for macros and `enum' constants, and for name-prefixes that
1912 follow a uniform convention.
1913
1914    For example, you should use names like `ignore_space_change_flag';
1915 don't use names like `iCantReadThis'.
1916
1917    Variables that indicate whether command-line options have been
1918 specified should be named after the meaning of the option, not after
1919 the option-letter.  A comment should state both the exact meaning of
1920 the option and its letter.  For example,
1921
1922      /* Ignore changes in horizontal whitespace (-b).  */
1923      int ignore_space_change_flag;
1924
1925    When you want to define names with constant integer values, use
1926 `enum' rather than `#define'.  GDB knows about enumeration constants.
1927
1928    Use file names of 14 characters or less, to avoid creating gratuitous
1929 problems on older System V systems.  You can use the program `doschk'
1930 to test for this.  `doschk' also tests for potential name conflicts if
1931 the files were loaded onto an MS-DOS file system--something you may or
1932 may not care about.
1933
1934 \1f
1935 File: standards.info,  Node: System Portability,  Next: CPU Portability,  Prev: Names,  Up: Writing C
1936
1937 Portability between System Types
1938 ================================
1939
1940    In the Unix world, "portability" refers to porting to different Unix
1941 versions.  For a GNU program, this kind of portability is desirable, but
1942 not paramount.
1943
1944    The primary purpose of GNU software is to run on top of the GNU
1945 kernel, compiled with the GNU C compiler, on various types of CPU.  The
1946 amount and kinds of variation among GNU systems on different CPUs will
1947 be comparable to the variation among Linux-based GNU systems or among
1948 BSD systems today.  So the kinds of portability that are absolutely
1949 necessary are quite limited.
1950
1951    But many users do run GNU software on non-GNU Unix or Unix-like
1952 systems.  So supporting a variety of Unix-like systems is desirable,
1953 although not paramount.
1954
1955    The easiest way to achieve portability to most Unix-like systems is
1956 to use Autoconf.  It's unlikely that your program needs to know more
1957 information about the host platform than Autoconf can provide, simply
1958 because most of the programs that need such knowledge have already been
1959 written.
1960
1961    Avoid using the format of semi-internal data bases (e.g.,
1962 directories) when there is a higher-level alternative (`readdir').
1963
1964    As for systems that are not like Unix, such as MSDOS, Windows, the
1965 Macintosh, VMS, and MVS, supporting them is usually so much work that it
1966 is better if you don't.
1967
1968    The planned GNU kernel is not finished yet, but you can tell which
1969 facilities it will provide by looking at the GNU C Library Manual.  The
1970 GNU kernel is based on Mach, so the features of Mach will also be
1971 available.  However, if you use Mach features, you'll probably have
1972 trouble debugging your program today.
1973