Line 1... |
Line 1... |
This is Info file standards.info, produced by Makeinfo version 1.67
|
This is standards.info, produced by Makeinfo version 3.12f from
|
from the input file ./standards.texi.
|
./standards.texi.
|
|
|
START-INFO-DIR-ENTRY
|
START-INFO-DIR-ENTRY
|
* Standards: (standards). GNU coding standards.
|
* Standards: (standards). GNU coding standards.
|
END-INFO-DIR-ENTRY
|
END-INFO-DIR-ENTRY
|
|
|
Line 120... |
Line 120... |
Accepting Contributions
|
Accepting Contributions
|
=======================
|
=======================
|
|
|
If someone else sends you a piece of code to add to the program you
|
If someone else sends you a piece of code to add to the program you
|
are working on, we need legal papers to use it--the same sort of legal
|
are working on, we need legal papers to use it--the same sort of legal
|
papers we will need to get from you. *Each* significant contributor to
|
papers we will need to get from you. _Each_ significant contributor to
|
a program must sign some sort of legal papers in order for us to have
|
a program must sign some sort of legal papers in order for us to have
|
clear title to the program. The main author alone is not enough.
|
clear title to the program. The main author alone is not enough.
|
|
|
So, before adding in any contributions from other people, please tell
|
So, before adding in any contributions from other people, please tell
|
us, so we can arrange to get the papers. Then wait until we tell you
|
us, so we can arrange to get the papers. Then wait until we tell you
|
Line 342... |
Line 342... |
File: standards.info, Node: Semantics, Next: Libraries, Up: Program Behavior
|
File: standards.info, Node: Semantics, Next: Libraries, Up: Program Behavior
|
|
|
Writing Robust Programs
|
Writing Robust Programs
|
=======================
|
=======================
|
|
|
Avoid arbitrary limits on the length or number of *any* data
|
Avoid arbitrary limits on the length or number of _any_ data
|
structure, including file names, lines, files, and symbols, by
|
structure, including file names, lines, files, and symbols, by
|
allocating all data structures dynamically. In most Unix utilities,
|
allocating all data structures dynamically. In most Unix utilities,
|
"long lines are silently truncated". This is not acceptable in a GNU
|
"long lines are silently truncated". This is not acceptable in a GNU
|
utility.
|
utility.
|
|
|
Utilities reading files should not drop NUL characters, or any other
|
Utilities reading files should not drop NUL characters, or any other
|
nonprinting characters *including those with codes above 0177*. The
|
nonprinting characters _including those with codes above 0177_. The
|
only sensible exceptions would be utilities specifically intended for
|
only sensible exceptions would be utilities specifically intended for
|
interface to certain types of printers that can't handle those
|
interface to certain types of printers that can't handle those
|
characters.
|
characters.
|
|
|
Check every system call for an error return, unless you know you
|
Check every system call for an error return, unless you know you
|
wish to ignore errors. Include the system error text (from `perror' or
|
wish to ignore errors. Include the system error text (from `perror' or
|
equivalent) in *every* error message resulting from a failing system
|
equivalent) in _every_ error message resulting from a failing system
|
call, as well as the name of the file if any and the name of the
|
call, as well as the name of the file if any and the name of the
|
utility. Just "cannot open foo.c" or "stat failed" is not sufficient.
|
utility. Just "cannot open foo.c" or "stat failed" is not sufficient.
|
|
|
Check every call to `malloc' or `realloc' to see if it returned
|
Check every call to `malloc' or `realloc' to see if it returned
|
zero. Check `realloc' even if you are making the block smaller; in a
|
zero. Check `realloc' even if you are making the block smaller; in a
|
Line 407... |
Line 407... |
comments in the source. The relevant data will be in variables, which
|
comments in the source. The relevant data will be in variables, which
|
are easy to examine with the debugger, so there is no point moving them
|
are easy to examine with the debugger, so there is no point moving them
|
elsewhere.
|
elsewhere.
|
|
|
Do not use a count of errors as the exit status for a program.
|
Do not use a count of errors as the exit status for a program.
|
*That does not work*, because exit status values are limited to 8 bits
|
_That does not work_, because exit status values are limited to 8 bits
|
(0 through 255). A single run of the program might have 256 errors; if
|
(0 through 255). A single run of the program might have 256 errors; if
|
you try to return 256 as the exit status, the parent process will see 0
|
you try to return 256 as the exit status, the parent process will see 0
|
as the status, and it will appear that the program succeeded.
|
as the status, and it will appear that the program succeeded.
|
|
|
If you make temporary files, check the `TMPDIR' environment
|
If you make temporary files, check the `TMPDIR' environment
|
Line 557... |
Line 557... |
version number proper starts after the last space. In addition,
|
version number proper starts after the last space. In addition,
|
it contains the canonical name for this program, in this format:
|
it contains the canonical name for this program, in this format:
|
|
|
GNU Emacs 19.30
|
GNU Emacs 19.30
|
|
|
The program's name should be a constant string; *don't* compute it
|
The program's name should be a constant string; _don't_ compute it
|
from `argv[0]'. The idea is to state the standard or canonical
|
from `argv[0]'. The idea is to state the standard or canonical
|
name for the program, not its file name. There are other ways to
|
name for the program, not its file name. There are other ways to
|
find out the precise file name where a command is found in `PATH'.
|
find out the precise file name where a command is found in `PATH'.
|
|
|
If the program is a subsidiary part of a larger package, mention
|
If the program is a subsidiary part of a larger package, mention
|
Line 1722... |
Line 1722... |
* Comments:: Commenting Your Work
|
* Comments:: Commenting Your Work
|
* Syntactic Conventions:: Clean Use of C Constructs
|
* Syntactic Conventions:: Clean Use of C Constructs
|
* Names:: Naming Variables and Functions
|
* Names:: Naming Variables and Functions
|
* System Portability:: Portability between different operating systems
|
* System Portability:: Portability between different operating systems
|
* CPU Portability:: Supporting the range of CPU types
|
* CPU Portability:: Supporting the range of CPU types
|
* System Functions:: Portability and "standard" library functions
|
* System Functions:: Portability and ``standard'' library functions
|
* Internationalization:: Techniques for internationalization
|
* Internationalization:: Techniques for internationalization
|
* Mmap:: How you can safely use `mmap'.
|
* Mmap:: How you can safely use `mmap'.
|
|
|
|
|
File: standards.info, Node: Formatting, Next: Comments, Up: Writing C
|
File: standards.info, Node: Formatting, Next: Comments, Up: Writing C
|
Line 1884... |
Line 1884... |
zero means continue them. */
|
zero means continue them. */
|
int truncate_lines;
|
int truncate_lines;
|
|
|
Every `#endif' should have a comment, except in the case of short
|
Every `#endif' should have a comment, except in the case of short
|
conditionals (just a few lines) that are not nested. The comment should
|
conditionals (just a few lines) that are not nested. The comment should
|
state the condition of the conditional that is ending, *including its
|
state the condition of the conditional that is ending, _including its
|
sense*. `#else' should have a comment describing the condition *and
|
sense_. `#else' should have a comment describing the condition _and
|
sense* of the code that follows. For example:
|
sense_ of the code that follows. For example:
|
|
|
#ifdef foo
|
#ifdef foo
|
...
|
...
|
#else /* not foo */
|
#else /* not foo */
|
...
|
...
|
Line 2136... |
Line 2136... |
fprintf (stderr, "error: ");
|
fprintf (stderr, "error: ");
|
fprintf (stderr, s, a1, a2, a3);
|
fprintf (stderr, s, a1, a2, a3);
|
}
|
}
|
|
|
In practice, this works on all machines, and it is much simpler than any
|
In practice, this works on all machines, and it is much simpler than any
|
"correct" alternative. Be sure *not* to use a prototype for such
|
"correct" alternative. Be sure _not_ to use a prototype for such
|
functions.
|
functions.
|
|
|
However, avoid casting pointers to integers unless you really need
|
However, avoid casting pointers to integers unless you really need
|
to. These assumptions really reduce portability, and in most programs
|
to. These assumptions really reduce portability, and in most programs
|
they are easy to avoid. In the cases where casting pointers to
|
they are easy to avoid. In the cases where casting pointers to
|
Line 2405... |
Line 2405... |
documented in one manual; but this does not mean each program should
|
documented in one manual; but this does not mean each program should
|
have its own manual. That would be following the structure of the
|
have its own manual. That would be following the structure of the
|
implementation, rather than the structure that helps the user
|
implementation, rather than the structure that helps the user
|
understand.
|
understand.
|
|
|
Instead, each manual should cover a coherent *topic*. For example,
|
Instead, each manual should cover a coherent _topic_. For example,
|
instead of a manual for `diff' and a manual for `diff3', we have one
|
instead of a manual for `diff' and a manual for `diff3', we have one
|
manual for "comparison of files" which covers both of those programs,
|
manual for "comparison of files" which covers both of those programs,
|
as well as `cmp'. By documenting these programs together, we can make
|
as well as `cmp'. By documenting these programs together, we can make
|
the whole subject clearer.
|
the whole subject clearer.
|
|
|
Line 2428... |
Line 2428... |
|
|
That is not as hard as it first sounds. Arrange each chapter as a
|
That is not as hard as it first sounds. Arrange each chapter as a
|
logical breakdown of its topic, but order the sections, and write their
|
logical breakdown of its topic, but order the sections, and write their
|
text, so that reading the chapter straight through makes sense. Do
|
text, so that reading the chapter straight through makes sense. Do
|
likewise when structuring the book into chapters, and when structuring a
|
likewise when structuring the book into chapters, and when structuring a
|
section into paragraphs. The watchword is, *at each point, address the
|
section into paragraphs. The watchword is, _at each point, address the
|
most fundamental and important issue raised by the preceding text.*
|
most fundamental and important issue raised by the preceding text._
|
|
|
If necessary, add extra chapters at the beginning of the manual which
|
If necessary, add extra chapters at the beginning of the manual which
|
are purely tutorial and cover the basics of the subject. These provide
|
are purely tutorial and cover the basics of the subject. These provide
|
the framework for a beginner to understand the rest of the manual. The
|
the framework for a beginner to understand the rest of the manual. The
|
Bison manual provides a good example of how to do this.
|
Bison manual provides a good example of how to do this.
|
Line 2652... |
Line 2652... |
are contained in a `#ifdef HAVE_LIBNCURSES' conditional:
|
are contained in a `#ifdef HAVE_LIBNCURSES' conditional:
|
|
|
* dispnew.c (init_display) [HAVE_LIBNCURSES]: If X, call tgetent.
|
* dispnew.c (init_display) [HAVE_LIBNCURSES]: If X, call tgetent.
|
|
|
Here is an entry for a change that takes affect only when a certain
|
Here is an entry for a change that takes affect only when a certain
|
macro is *not* defined:
|
macro is _not_ defined:
|
|
|
(gethostname) [!HAVE_SOCKETS]: Replace with winsock version.
|
(gethostname) [!HAVE_SOCKETS]: Replace with winsock version.
|
|
|
|
|
File: standards.info, Node: Man Pages, Next: Reading other Manuals, Prev: Change Logs, Up: Documentation
|
File: standards.info, Node: Man Pages, Next: Reading other Manuals, Prev: Change Logs, Up: Documentation
|
Line 2743... |
Line 2743... |
The `configure' script must record the configuration options so that
|
The `configure' script must record the configuration options so that
|
they affect compilation.
|
they affect compilation.
|
|
|
One way to do this is to make a link from a standard name such as
|
One way to do this is to make a link from a standard name such as
|
`config.h' to the proper configuration file for the chosen system. If
|
`config.h' to the proper configuration file for the chosen system. If
|
you use this technique, the distribution should *not* contain a file
|
you use this technique, the distribution should _not_ contain a file
|
named `config.h'. This is so that people won't be able to build the
|
named `config.h'. This is so that people won't be able to build the
|
program without configuring it first.
|
program without configuring it first.
|
|
|
Another thing that `configure' can do is to edit the Makefile. If
|
Another thing that `configure' can do is to edit the Makefile. If
|
you do this, the distribution should *not* contain a file named
|
you do this, the distribution should _not_ contain a file named
|
`Makefile'. Instead, it should include a file `Makefile.in' which
|
`Makefile'. Instead, it should include a file `Makefile.in' which
|
contains the input used for editing. Once again, this is so that people
|
contains the input used for editing. Once again, this is so that people
|
won't be able to build the program without configuring it first.
|
won't be able to build the program without configuring it first.
|
|
|
If `configure' does write the `Makefile', then `Makefile' should
|
If `configure' does write the `Makefile', then `Makefile' should
|
Line 3063... |
Line 3063... |
but we keep them because they are standard.) Use `CPPFLAGS' in any
|
but we keep them because they are standard.) Use `CPPFLAGS' in any
|
compilation command that runs the preprocessor, and use `LDFLAGS' in
|
compilation command that runs the preprocessor, and use `LDFLAGS' in
|
any compilation command that does linking as well as in any direct use
|
any compilation command that does linking as well as in any direct use
|
of `ld'.
|
of `ld'.
|
|
|
If there are C compiler options that *must* be used for proper
|
If there are C compiler options that _must_ be used for proper
|
compilation of certain files, do not include them in `CFLAGS'. Users
|
compilation of certain files, do not include them in `CFLAGS'. Users
|
expect to be able to specify `CFLAGS' freely themselves. Instead,
|
expect to be able to specify `CFLAGS' freely themselves. Instead,
|
arrange to pass the necessary options to the C compiler independently
|
arrange to pass the necessary options to the C compiler independently
|
of `CFLAGS', by writing them explicitly in the compilation commands or
|
of `CFLAGS', by writing them explicitly in the compilation commands or
|
by defining an implicit rule, like this:
|
by defining an implicit rule, like this:
|
Line 3076... |
Line 3076... |
ALL_CFLAGS = -I. $(CFLAGS)
|
ALL_CFLAGS = -I. $(CFLAGS)
|
.c.o:
|
.c.o:
|
$(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) $<
|
$(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) $<
|
|
|
Do include the `-g' option in `CFLAGS', because that is not
|
Do include the `-g' option in `CFLAGS', because that is not
|
*required* for proper compilation. You can consider it a default that
|
_required_ for proper compilation. You can consider it a default that
|
is only recommended. If the package is set up so that it is compiled
|
is only recommended. If the package is set up so that it is compiled
|
with GCC by default, then you might as well include `-O' in the default
|
with GCC by default, then you might as well include `-O' in the default
|
value of `CFLAGS' as well.
|
value of `CFLAGS' as well.
|
|
|
Put `CFLAGS' last in the compilation command, after other variables
|
Put `CFLAGS' last in the compilation command, after other variables
|
Line 3643... |
Line 3643... |
A category line consists of a tab and a reference to a special Make
|
A category line consists of a tab and a reference to a special Make
|
variable, plus an optional comment at the end. There are three
|
variable, plus an optional comment at the end. There are three
|
variables you can use, one for each category; the variable name
|
variables you can use, one for each category; the variable name
|
specifies the category. Category lines are no-ops in ordinary execution
|
specifies the category. Category lines are no-ops in ordinary execution
|
because these three Make variables are normally undefined (and you
|
because these three Make variables are normally undefined (and you
|
*should not* define them in the makefile).
|
_should not_ define them in the makefile).
|
|
|
Here are the three possible category lines, each with a comment that
|
Here are the three possible category lines, each with a comment that
|
explains what it means:
|
explains what it means:
|
|
|
$(PRE_INSTALL) # Pre-install commands follow.
|
$(PRE_INSTALL) # Pre-install commands follow.
|
Line 3667... |
Line 3667... |
|
|
Typically, a pre-uninstall command would be used for deleting entries
|
Typically, a pre-uninstall command would be used for deleting entries
|
from the Info directory.
|
from the Info directory.
|
|
|
If the `install' or `uninstall' target has any dependencies which
|
If the `install' or `uninstall' target has any dependencies which
|
act as subroutines of installation, then you should start *each*
|
act as subroutines of installation, then you should start _each_
|
dependency's commands with a category line, and start the main target's
|
dependency's commands with a category line, and start the main target's
|
commands with a category line also. This way, you can ensure that each
|
commands with a category line also. This way, you can ensure that each
|
command is placed in the right category regardless of which of the
|
command is placed in the right category regardless of which of the
|
dependencies actually run.
|
dependencies actually run.
|
|
|
Line 3778... |
Line 3778... |
know what other files to get.
|
know what other files to get.
|
|
|
|
|
|
|
Tag Table:
|
Tag Table:
|
Node: Top988
|
Node: Top964
|
Node: Preface1531
|
Node: Preface1507
|
Node: Intellectual Property2558
|
Node: Intellectual Property2534
|
Node: Reading Non-Free Code2933
|
Node: Reading Non-Free Code2909
|
Node: Contributions4665
|
Node: Contributions4641
|
Node: Design Advice6659
|
Node: Design Advice6635
|
Node: Compatibility7176
|
Node: Compatibility7152
|
Node: Using Extensions8687
|
Node: Using Extensions8663
|
Node: ANSI C10189
|
Node: ANSI C10165
|
Node: Source Language11425
|
Node: Source Language11401
|
Node: Program Behavior12918
|
Node: Program Behavior12894
|
Node: Semantics13627
|
Node: Semantics13603
|
Node: Libraries17381
|
Node: Libraries17357
|
Node: Errors18616
|
Node: Errors18592
|
Node: User Interfaces19839
|
Node: User Interfaces19815
|
Node: Option Table26586
|
Node: Option Table26562
|
Node: Memory Usage40675
|
Node: Memory Usage40651
|
Node: Writing C41669
|
Node: Writing C41645
|
Node: Formatting42508
|
Node: Formatting42486
|
Node: Comments45780
|
Node: Comments45758
|
Node: Syntactic Conventions49078
|
Node: Syntactic Conventions49056
|
Node: Names52016
|
Node: Names51994
|
Node: System Portability53752
|
Node: System Portability53730
|
Node: CPU Portability55528
|
Node: CPU Portability55506
|
Node: System Functions57689
|
Node: System Functions57667
|
Node: Internationalization62793
|
Node: Internationalization62771
|
Node: Mmap65941
|
Node: Mmap65919
|
Node: Documentation66646
|
Node: Documentation66624
|
Node: GNU Manuals67204
|
Node: GNU Manuals67182
|
Node: Manual Structure Details71091
|
Node: Manual Structure Details71069
|
Node: NEWS File72421
|
Node: NEWS File72399
|
Node: Change Logs73102
|
Node: Change Logs73080
|
Node: Change Log Concepts73819
|
Node: Change Log Concepts73797
|
Node: Style of Change Logs75587
|
Node: Style of Change Logs75565
|
Node: Simple Changes77141
|
Node: Simple Changes77119
|
Node: Conditional Changes78332
|
Node: Conditional Changes78310
|
Node: Man Pages79709
|
Node: Man Pages79687
|
Node: Reading other Manuals81328
|
Node: Reading other Manuals81306
|
Node: Managing Releases82112
|
Node: Managing Releases82090
|
Node: Configuration82848
|
Node: Configuration82826
|
Node: Makefile Conventions89788
|
Node: Makefile Conventions89766
|
Node: Makefile Basics90468
|
Node: Makefile Basics90446
|
Node: Utilities in Makefiles93637
|
Node: Utilities in Makefiles93615
|
Node: Command Variables95773
|
Node: Command Variables95751
|
Node: Directory Variables99273
|
Node: Directory Variables99252
|
Node: Standard Targets110149
|
Node: Standard Targets110129
|
Node: Install Command Categories120690
|
Node: Install Command Categories120669
|
Node: Releases125263
|
Node: Releases125242
|
|
|
End Tag Table
|
End Tag Table
|