GNU coding standard

xiaoxiao2021-03-06  45

GNU coding standard

Quote Private Programs Do not use the work code (or any other private programs) for you in the GNU in any case. If you have some blurred memories for a UNIX program, this is not mimicing it because of your absolute writing program, but try to organize it internally, because this will make your work in detail It is different from UNIX version. For example, UNIX tools typically optimize to use the least amount of memory; if you prefer to increase the speed, your program will have a lot. You can save the entire input file in the kernel and scan in memory instead of using STDIO. Using, smarter algorithms updated than a UNIX program. Do not use temporary files. Complete the task in a scan rather than the scan (I am in the Assembler (IMBLER). Alternatively, emphasizing the simplicity rather than the speed. For some applications, today's computer is enough to use a simple algorithm. Or pay attention to generality. For example, UNIX programs typically use static tables and fixed-size strings, which leads to an inexchable restriction; replaced with dynamic allocation. Confirm that your program processes the input file as empty and other funny situations. Add a program language to increase scalability and use the language to complete a part of the program. Or modify a part of the program into a separate library. Or use a simple waste collector instead of exactly tracking when the memory is released, or a new GNU tool such as OBSTacks is used.

Accepting the dedication of others If anyone sends you to the code you are writing a program, we need to allow the legal instrument to use - we will need the same legal instrument from you. Each important contributor to the program must sign a legal instrument so that we can give the program a clear title. Only the main author is not enough. So, tell us before adding any sharing from others to the program so that we can make arrangements to obtain documents. Before you actually use the contribution, wait until we tell you that we have received the signature instrument. This is also applicable to the release before you apply to your release. If you receive a patch that fix bugs, and they do the main modifications, we need to provide legal instruments. You don't need to make documents for a few rows of lines here, because there is no meaning to achieve copyright. Also, if you get some ideas from the suggestion, you don't need a document. For example, if you write a different solution for a program, you don't need to get licensed text. I know this is very troublesome; it is very troublesome for us. But if you don't wait, you may be misunderstood, if this contributor's employer is not willing to sign a waiver, what should I do? You may have to remove the code again! The worst case is if you forget to tell us other contributors, we may happen in the court.

The modification log maintains a modification log for each directory to describe the modification of this directory's next source file. The purpose of doing this is to make people looking for bugs in the future can guide roughly those modifications lead to errors. Typically, a new bug can be found in the recently modified modification. More important things, modify the log helps to eliminate the conceptual inconsistency between the different parts of the program; they can tell us the history of the concept conflict. Use the Emacs Command M-X Add-Change to create a new entry in the modified day. An entry should contain an asterisk, the name of the modified file, and the modified function, variable or anything that is being modified in parentheses. Behind parentheses is a colon and a modification of your function or variable. Separate unrelated entries with a blank line. If the two entries reflect the same modification, they work together, so don't use space between them. If the subsequent entries are for the same file, then you can ignore the asterisk of the file name. Here are some examples: * register.el: return nil. (Jump-to-register): likewise. * Sort.el (sort-subr): return nil. * Tex-mode.el (Tex- BIBTEX-FILE, TEX-FILE, TEX-Region: Restart The Tex Shell IF Process IS GONE OR Stopped: New function. * expr.c (store_one_arg): Round size Up for move_block_to_reg. ( Expand_call): Round Up when Emitting Use Insns. * Stmt.c (assign_parms): Round size Up for move_block_from_reg. There is no need to narrate the modified full directory and how they work together. Take these instructions as a note to the code better. That is to say why just give "new function" is enough; in the source code, the annotation with the function is in the note that it is doing. However, it is sometimes written to describe the overall purpose of a large bunch of modifications to describe their overall purpose. On concept, you can explain the modified log as a different "undo list" that explains the original version with the current version. People can read the current version; they don't need to modify the log telling them what it is. They get different clear explanations from early versions of the day. In a simple manner, modify the call sequence of the function, and you modify all the calls to the function, you don't have to create a separate entry for all calls. As long as you write "All Callers Changed." In an entry called the function. When you only modify your annotation or document string, you write an entry for this file without having to mention the function, it is enough. Just write "DOC FIX.". You don't have to maintain a logging log for a document file. This is because the documentation is not so easy to be affected by the incorrect mistakes. Documents are not consisting of those that must be interacting with accurate engineering methods; to modify an error, you don't need to know the history of this error. Compatibility with other implementations As a special case, for tools and libraries in the GNU, they should be compatible with the corresponding part of Berkeley UNIX, and if the standard C defines their behavior, they should be compatible with standard C, if POSIX The specification defines their behavior, which should also be compatible with the POSIX specification. When these criteria conflict, it is useful to provide compatibility patterns for each standard. Standard C and POSIX prohibits any form of extension. Free extension freely, and select '-ansi' or '-compatible' comes in to turn off your extension. But if the extension is likely to cause any actual program or script crash, it may actually be compatible upward. Try redefining its interface.

When a feature is only used by the user (without the program or command file), and it is not good in UNIX, it is free to use completely different and better ways. (For example, use Emacs instead of VI.) But also provides compatibility mode is still very good. (Now there is free VI implementation, we offer it.) Welcome to provide useful features that Berkeley Unix is ​​available. Additional features in Unix may be useful, but we prioritize those UNIX already have functions.

Makefile Practice This chapter describes the practice of writing makefile as a GNU program. Makefile General practices Each Makefile should include this line: shell = / bin / sh to avoid the trouble of avoiding the system that inherits the SHELL variable from the environment. (GNU Make will never have this problem.) Do not assume '.' The path appears in the path used to find executable commands. When you need to run a program as your package during Make, if the program is created as a part of the make, make sure it uses './', or if the file is not changed source code Part, make sure it uses' '$ (srcdir) /'. If you use the option '-srcdir' when run 'configure', the difference between './' and '$ (srcdir) /' is important. The form of the form: foo.1: foo.man sedscript sed -e sedscript foo.man> foo.1 will cause errors if the current directory is not the source code directory, because 'foo.man' and 'sedscript' Not in the current directory. When using GNU Make, since the source file is there, 'make' automatic variable '$ <' will represent it, so if there is only one dependency file, relying on 'vpath' to find the source file is still feasible. (Many versions of Make only sets '$ <'.) The following Makefile target: foo.o: bar.c $ (cc) -i. -I $ (srcdir) $ (cflags) -c bar .c -o foo.o will be replaced by the following goals: foo.o: bar.c $ (cc) $ (cflags) $ <-o $ @ to make 'vPath' work correctly. When the target contains more dependent files, the easiest way to use '$ (srcdir)' to work properly. For example, the target provided for 'foo.1' is preferably written as follows: foo.1: foo.man sedscript sed -s $ (srcdir) / sedscript $ (srcdir) /foo.man> foo.1makefile tools Writing can be in SH instead of Makefile commands running in CSH, and any shell script, such as configure. Do not use any KSH or Bash special features. For CONFIGURE scripts and makefile rules provided for creation and installation, do not use any tools directly, except for the following: Cat CMP CP Echo EGREP EXPR GREPLN MKDIR MV PWD RM RMDir Sed Test Touch insists on using these programs to support options. For example, because many systems do not support 'mkdir -p', although it may be somewhat convenient, don't use it. The Makefile rules provided for creation and installation can also use compilers and related programs, but should be replaced by MAKE variables so that users can be replaced. Here is some of what we do: Ar Bison CC Flex Install Ld Lexmake Makeinfo Ranlib Texi2DVI Yacc When you use Ranlib, you should test whether it exists, and only runs it in its existence, so that it is released The version can work in systems that do not have RANLIB. If you use a symbolic connection, you should implement an alternate means for systems without symbolic connections. You can use the tools you can confirm on those systems that exist on those systems in the partial (or script) intended to use the Makefile for a particular system.

All GNU programs for users provided by users should contain the following targets in their makefile: 'all' compiles the entire program. It should be the default goal. This goal does not need to recreate any document files; Info files are included in the release, while only create a DVI file when the user explicitly requires the DVI file. The 'install' compiler and copies files such as executables, library files to their location that should exist in practical applications. If there is a simple test that can detect if the program is properly installed, this goal will first run this test. If the file installation directory does not exist, this command will create such a directory. They include directories indicated by variable prefix and exec_prefix, as well as all of the required directories. One way to accomplish this task is done by the target installDIRS in the manner described later. Use '-' before any user installed the MAN manual, so that Make ignores all errors. Errors will appear in systems that do not have a UNIX MAN manual document system. The way to install the Info file is to copy them into '$ (InfoDir) with $ (install_data). (See the variables provided to indicate the command), and if there is a program install-info exists, then it runs. Install-Info is a script that edits the Info 'Dir' file to add a given INFO file to a script of the directory item; it will be a part of the TexInfo package. Below is a simple rule for installing an info file: $ (infodir) /foo.info: foo.info # There be a new info file in. THAN in srcdir. -IF test -f foo.info; THEN D = .; / Else d = $ (srcdir); Fi; / $ (install_data) $$ d / foo.info $ @; / # run install-info online @ t u ue i 'instead of just prepending' 'to the # line sowe notice real errors from install-info. # We use' $ (shell) -c 'Because Some shells do not # fail gracefully when it is an unknown command. if $ (shell) -c' install -info --Version '/> / dev / null 2> & 1; THEN / Install-Info - Infodir = $ (Infodir) $ D / FOO.INFO; / ELSE TRUE; Fi'UnInStall delete all by' INSTALL 'All installed files created by the target (but do not include those created by targets such as' make all', without being installed). 'Clean' removes all files created during the creation program from the current directory. Don't delete files for those records. Some files may be created during the creation process, but because they are published together, it is usually not created during the creation process, such files need to be retained. If the '.dvi' file is not part of the release version, it deletes them. 'Distclean' removes all files created during the configuration and creation process from the current directory. If you unpack the source code and create a program without adding any other file, 'make distclean' will only keep the files in the release version. 'MostlyClean' is similar to 'Clean', may not delete a few people usually do not want to recompile.

For example, GCC's 'MostlyClean' target does not delete 'libgcc.a' because rarely need to recompile and recompile will spend a lot of time. 'Realclean' removes all files that can be recreated by makefile from the current directory. This usually includes all files deleted by distclean, as well as the C source file, tag tables, info files generated by Bison, and more. However, there is an exception: even if 'onfigure' is recreated by using the rules in Makefile, 'AKE Realclean' does not delete 'onfigure' more generally, 'Ake Realclean' does not delete the existence to run 'onfigure' Anything and then start creating a program. 'AGS' is updated for this program (tags table). 'Nfo' Generates all required INFO files. The best way to write this rule is: info: foo.infofoo.info: foo.texi chap1.texi chap2.texi $ (makeinfo) $ (srcdir) /foo.texi You must define variables Makefo in Makefile. It should run the program MakeInfo, which is part of the TexInfo release. 'Vi' For all xinfo document VI files, such as: DVI: foo.dvifoo.dvi: foo.texi chap1.texi chap2.texi $ (texi2dvi) $ (srcdir) /FOO.TEXI you must define variable texi2dvi in ​​makefile. It should run the program Texi2DVI, which is also part of the TexInfo release version. As another selection, just write dependencies and allow the GNU Make to provide this command. 'IST' Create a release TAR file for this program. The TAR file will be set to make the file name in the TAR file with the child directory name, which is the name of the published. This name can contain version numbers. For example, the Publish TAR file of GCC version 1.40 will be unpackded in subdirectory named 'GCC-1.40'. The easiest way to complete this task is to create a subdirectory with an appropriate name, install the correct file into the directory using LN or CP, and then the subdirectory of TAR. Target DIST should explicitly depend on all non-source files in the release of the release to ensure that they are not outdated in the publishing version. See making a release package 'heck' (if any) performs self-test. Users must have prior to running tests, but do not have to create programs before the installer; you should write a self-test so that they do not work before being created. For programs suitable for the following targets, it is recommended that you provide them in accordance with common names. 'NstallCheck' (if any) performs installation monitoring. The user must create and install the program before running the detection. You should not assume that '(bindir)' appears in the search path. 'NstallDirs' adds a target called 'InstallDirs' to create a directory of the installation file and their parent directory. There is a script called 'mkinstallDirs' to facilitate this; you can find it in the Texinfo package.

You can use rules like the following: # Make sure all installation directories (eg $ (bindir)) # actually exist by making them if necessary.installdirs: mkinstalldirs $ (srcdir) / mkinstalldirs $ (bindir) $ (datadir) / $ (libdir) $ (infodir) / $ (MANDIR) The variable Makefile provided by the specified command should provide variables to overwrite some commands, options, and more. In particular, you should run most of the tool programs through variables. Therefore, if you use Bison, define a default to set the variable Bison that is set by 'bison = bison', and you need to use Bison's all places to reference it through $ (bison). In this manner, file management tools: ln, rm, mv, etc. do not need to be referenced by variables because users do not need other programs to replace them. Each program name variable should have a corresponding variable to provide options for the program. The following is an option variable name for the 'Flags' to the program name variable name - for example, BisonFlags. (Name CFLAGS is an exception to this rule, but because it is a standard, it retains it.) Use cppflags in any compiler in the compilation command, in any connection, direct use of LD Use ldflags in. If there are some C compiler options that must be used in order to correctly compile certain files, do not include them in cflags. The user wants to freely specify the value of CFLAGS. The alternative is to pass the options to the C compiler by defining a hidden rule in the compilation command line or by defining a hidden rule to define a hidden rule. Cflags = -gall_cflags = -i. $ (Cflags) .co: $ (cc) -c $ (cppflags) $ (all_cflags) $

The variable installation directory provided for the installation directory should always be named by variables to make it easy to install the package in other non-standard locations. The standard names of these variables are: 'prefix' is used to construct the default value of the following variables. The default value of Prefix should be '/ usr / local' (at least it is now it). 'Exec_prefix' 'is used to construct the default value of the following variables. The default value of EXEC_PREFIX should be $ (prefix). In general, $ (exec_prefix) refers to directories for storing files related to machines (such as executable files and subripers), and $ (Prefix) is used directly for other directories. 'Bindir' is used to store the executable directory of the user can run. Generally, '/ usr / local / bin' should be written, but should be written '$ (exec_prefix) / bin'. 'Libdir' is used to install the executable of the executable running by the program, not by the user. The Object file and the Object code library should also be stored in this directory. The intent for providing this directory is to store applications for special machine structures, but do not have to appear in the command path. The value of libdir is usually '/ usr / local / lib', but should be written '$ (exec_prefix) / lib'. 'DATADIR' Directory for read-only data files that need to be accessed at runtime. This catalog is used to store files with machines used. It is usually '/ usr / local / lib', but should be written '$ (prefix) / lib'. 'StateDir' is used to install the directory of the data file that needs to be modified at runtime. These files should be independent with the machine types used, and should be able to download between different machines on the network installation. It usually should be '/ usr / local / lib', but should be written '$ (prefix) / lib'. 'Includedir' is used to store directories that will be introduced by the user program with C pre-processed instruction '#include'. It should usually be '/ usr / local / include', but should be written '$ (prefix) / include'. In addition to GCC, most compilers are not in '/ usr / local / include' to find head files. So the installation of the header file in this way is only suitable for GCC. However, some libraries are designed to work together with other compilers. They should install their header files in two places, one is given by includedir, and the other is given by OldInCludedIr. 'OldInCludedir' is a directory for installing the header file except for the GCC. This should usually be '/ usr / incrude'. The Makefile command should detect if the value of OldInCludedir is empty. If it is empty, the makefile command should not try to use OldInCludedir; makefile commands should give up the second installation of the header file. Unless the header is from the same package, the package should not replace the existing header file. So if your FOO package provides a header file 'foo.h', and if it does not appear in the oldincludedir directory or 'foo.h' in the oldincludedir directory comes from with the foo package, then the FOO package should take the header file. Install into OldInCludedir. In order to determine whether 'foo.h' comes from the FOO package, a special string can be placed in a file as part of the annotation, and the string is searched after using GREP. 'Mandir' (if present) This package is installed in the directory of the Man book. It should contain suffixes corresponding to the correct manual part - for a tool is usually '1'. It is generally '/ usr / local / man / man1', but you should write it into: '$ (prefix) / man / man1'. 'Man1dir' Installs the first part of the MAN manual. 'Man2dir 'Install the directory of the second part of the MAN manual. '...' If the package needs to install the MAN manual to multiple parts of the manual system, use these names to replace 'mandir'.

Don't use the MAN manual as the main documentation of the GNU software. Use TexInfo writing documents to replace it. The MAN manual is just because people are in UNIX, it is just a secondary application, and the GNU software is only exists. 'Manext' is an extension of the file of the MAN manual that needs to be installed. It should be a point plus an appropriate number; usually it should be: '. 1'. 'Man1ext' will be installed to the extension of the file in the MAN manual. 'Man2ext' will be installed to the extension of the file of the second part of the MAN manual. '...' If the package needs to install the MAN manual to multiple parts of the manual system, use these names instead 'Manext'. 'Infodir' is the directory of the INFO file for this package. In the default, it should be '/ usr / local / info', which should be written as '$ (prefix) / info'. 'Srcdir' is used to compile the source code. The value of this variable is usually inserted by the ConfigureShell script. For example: # Common prefix for installation directories # NOTE:. This directory must exist when you start the install.prefix = / usr / localexec_prefix = $ (prefix) # Where to put the executable for the command 'gcc'.bindir = $ ( Exec_prefix) / bin # Where to put the directories buy by the compiler.libdir = $ (exec_prefix) / lib # Where to put the info files.infodir = $ (prefix) / info If your program is given in a standard user A large number of files are installed in the directory, which may use some files for the program to store them to the subdirectory. If you do this, you should overwrite the Install rule to create these subdirectories. Do not expect users to include subdirectory names in the values ​​of variables listed above. The intent for providing a unified variable name collection for the installation directory is to make the user can specify the identical value for some different GNU packets. In order to make these regulations become useful, all packages must be designed to work effectively when they do this.

The configuration is how each GNU publishing version should have a shell script called Configure. You need to tell this script as a parameter in that machine and system. Script Configure must log configuration information so that they can affect compilation. One way to do is to connect a standard name such as 'config.h' and the correct configuration file that matches the selected system. If you use this technology, you should not contain files named 'config.h' in the release version. This is to ensure that users cannot create it before configuring programs. Another thing that Configure can do is editing makefile. If you do this, you cannot contain files named 'makefile' in the release version. Use 'makefile.in' instead of it, and 'makefile.in' provides input for Configure editing. Similarly, this is to ensure that users cannot create it before configuring programs. If configure generates 'makefile', 'makefile' should include a target named 'Makefile', which will re-run configure to obtain the same configuration information as the last configured configuration. The file read by configure should be listed as a dependency file and is listed in 'makefile'. All files generated by the Configure script should include a note to illustrate that they are automatically generated by Configure. This is to ensure that users will not try to modify them. Script Configure should write a file called 'config.status', which gives those configuration options in the last configuration of the program. This file should be a shell script, if it is running it, regenerates the same configuration. Script Configure should accept the option of '--srcdir = dirname' to indicate that the source code can be found in that directory (if the source code is not in the current directory). This makes it possible to create programs in separate in the case where the actual code directory is not modified. If the user does not give '--srcdir', Configure will find source files in '.' And '..'. If it discovers the source file in one of the above places, it should use them there. Otherwise, it should report that it does not find the source file and exits in a non-zero state. Typically, the simple way to support '--srcdir' is to define the definition of a VPATH that is placed in the Makefile. There may be some rules that need to be explicitly referenced to specify the source code directory. In order to achieve this, configure can add a variable named srcdir to makefile, which is a given directory. Script Configure should also provide an option that can indicate that the program is created for that system. This option looks like: CPU-Company-System For example, a Sun 3 may be 'M68k-Sun-SunOS4.1'. Script Configure needs to explain all of the simplified description of the machine. Therefore, 'Sun3-SunOS4.1' should be a valid alias. This is also the case, because SunOS is BSD-based and no other BSD systems are used for Sun. For many programs, since Ultrix and BSDs are rarely noticed, 'vax-dec-ultrix' will be an alias of 'Vax-Dec-BSD'. But a few programs may need to distinguish them. Here is a shell script called 'config.sub', you can use it as a subroutine to check the system type and standardize the alias. Other options are allowed to indicate more details of software or hardware about machines: '- with-pack' package package will be installed, so configure this package to work with Package. Package may take value including 'x', 'gnu-as' (or 'GAS'), 'gnu-ld', 'gnu-libc' and 'GDB'.

'- NFP' target machine has no floating point number processor. '- The assembler of the Gas' target machine is the assembler of GAS, GNU. This option is out of time; replaced with '--with-gnu-as'. '--X' target machine has installed an X Window system. This option is out of time; replaced with '--with-x' INSTEAD. All configure scripts should accept all of these Details options, regardless of whether they will affect the specific packets of the hand. In particular, they should accept any options starting with '--with-'. This is because this allows users to configure the entire GNU source tree with the same option. A package as part of the compilation may support cross-compliation. In this case, the host and target machine of the program may be different. Configure typically uses the specified system type as a host and target machine, so you will create a program that runs on the machine that runs its machine type. Create a cross-compiler, cross-assembler, or your own program, is done by giving the option '--host = hosttype' when running configure. It indicates the host name without affecting the target machine. The syntax of HostType is the same as before. Because the entire operating system is configurable for interoperability, it is not necessary to accept the option '--host' for interoperability. Some programs automatically configure themselves. If your program is set to this, your Configure script only needs to simply ignore most of its parameters. Use the language other than the language other than C which is used as a non-standard feature: it will bring trouble to the user. Even if GCC supports other languages, users may also feel inconvenient because of their compilers who have to install other languages. So please use the C language. This rule has three exceptions: if some programs include an interpreter of a special language, you can use this language. Therefore, GNU Emacs contains no problems with code written with Emacs Lisp, because GNU Emacs contains a Lisp interpreter. If a tool is written for a language, you can use that language. This is because those who need to create this tool must be those who have already installed other languages. If an application is not very widely concerned, the application is not particularly important.

Formatting your source code puts the left flower parenthesis of the beginning of the C function to the zippers and avoids placing any other left flower brackets, left brackets or left brackets. Some tools look for the starting point of the C function by looking for the left flower brackets in the column. These tools will not be able to handle the code that is typically typed in this way. For function definitions, put the starting characters of the function name to the column column are equally important. This helps any lookup function definition and may help some tools identify them. Therefore, the correct format should be: Static Char * Concat (S1, S2) / * Name Starts in Column Zero Here * / CHAR * S1, * S2; {/ * Open Brace In Column Zero Here * / ...} or If you want to use standard C, the defined format is: static char * control (char * s1, char * s2) {...} In standard C, if the parameter cannot be placed in a row, follow The way they separate them: INTLOTS_OF_ARGS (Int A_Integer, long a_long, short a_short, double a_double, float a_float) ... For the function body, we hope that it places it as follows: IF (x win (x, y, z) && remaining_condition) to avoid the occurrence of two different priority operators in the same alignment. For example, don't write: mode = (Inmode [J] == VoidMode || GET_MODE_SIZE (OUTMODE [J])> GET_MODE_SIZE (INMODE [J])? OUTMODE [J]: Inmode [J]); Additional Braces to make text indentation can show this nested: mode = (inMode [j] == voidmode || (get_mode_size (outmode [j])> get_mode_size (Inmode [J]))? Outmode [J ]: Inmode [J]); Inserting extra parentheses to make Emacs can correctly align them.

For example, if you have finished indentation, then they look good, but Emacs will mix them together: v = rup-> ru_utime.tv_sec * 1000 rup-> ru_utime.tv_usec / 1000 rup-> ru_stime.tv_sec * 1000 RUP-> RU_STIME.TV_USEC / 1000; But add a group of parentheses to solve this problem: v = (rup-> ru_utime.tv_sec * 1000 rup-> ru_utime.tv_usec / 1000 rup-> ru_stime.tv_sec * 1000 rup-> ru_stime .tv_usec / 1000); Type of DO-WHILE statement in accordance with the following: Do {a = foo (a);} while (a> 0); follow the logical relationship (not in the function) use the paper character (Control- L) to divide the program into a page. How long is the page is not important because they don't have to be placed in a print page. Paper strips should appear separately in a row.

Write a comment for your work, each program should be shorter, indicating the end of its function. For example: 'FMT - Filter for Simple Filling of Text'. Write a comment for each function to explain what the function has done, which kinds of parameters, parameter possible values, and use. If you use a C language type in a common manner, it is not necessary to rewrite the meaning of the C parameter declaration. If it uses any non-standard things (for example, a parameter for a type of char * actually gives a second character of a string, not the first character, address), or may result in function Any possible value for work (eg, not guaranteed a string containing a new row), confirm that they have been described. If there is an important return value, it is also necessary to explain it. Please add two spaces after your comment so that the EMACS sentence naming. Also, please write a complete sentence and make the first word start with uppercase letters. If the identifier consisting of lowercase letters appears in the beginning of the sentence, don't turn it into uppercase! Modifying spelling constitutes a different identifier. If you don't want the sentence to start with lowercase letters, you can write down different sentences (for example, "The Identifier Lower-Case IS ..."). If you use the parameter name to explain the parameter value, the annotation of the function will be clearer. The variable name itself should be lower-written, but when you talk about its value rather than the variable itself, use uppercase letters. Therefore, "the inode number node_num" is better than "An inode". It is usually not necessary to re-refer the name of the function in the comment before the function, because the reader can see it himself. One possible exception is: The comment is too long, so that the function itself is extruded out of the bottom end of the screen. For each static variable, it should be provided below: / * Nonzero Means Truncate Lines in The Display; Zero Means Continue the. * / Int truncate_Lines; unless '#ENDIF' is a no nested and very short (only a few The condition of the line, each '#ndif' should contain a comment. Note Should indicate the conditions it end, including its meaning. '#ELSE' should contain a note that explains the meaning of the subsequent code. For example: #ifdef foo ... # else / * not foo * / ... # ENDIF / * NOT foo * / but instead, according to the following method is '#ifndef' write comments: #ifndef foo ... # Else / * foo * / ... # Endif / * foo * /

Clearly use the C language ingredients to explicitly declare all parameters of the function. Don't ignore them because they are integers. The declaration of the external function to the function in the source file should appear in the same place near the file (where the first function definitions is defined). Or other statements should appear in the header file. Do not place an external statement in a function. In the past, a common practice is to use the same partial variable (such as a variable named TEM) in the same function to different values. But now, a better way is to define each different purpose. Local variables and give them a more meaningful name. This is not only the program is more likely to understand, it will also be optimized by a good compiler. You can also put the declaration of local variables into it. The smallest range. This can make the program clearer. Do not use local variables and parameters that can mask the global identifier. Do not declare multiple variables in a declaration of rows. In each line, each line begins with a new statement For example, you should: int Foo, Bar; and should: int foo, bar; or: int foo; int bar; (if they are global variables, you should add a note before each of them.) You nest another IF-ELSE statement in an IF statement, always enclose IF-ELSE with curly brackets. Therefore, do not write: if (foo) IF (bar) win (); else Lose (); Always write: if (foo) {if (bar) win (); else Lose ();} If you nest in the ELSE statement, you can write else if: if: if: IF as below ) ... Else if (bar) ... Corrive into the THEN part of the else IF in the same indentation method as the code of the THEN, or nesting the IF in the currency parentheses: if (foo ... else {if (bar) ...} Do not explain the structural identification and variables or structural programs and type definitions (TYPEDEF) in the same statement. Separate the structure tester, and then define variables or Define type. Try to avoid assignment in the conditions of IF. For example, do not write: if ((foo = (char *) Malloc (SizeOf * foo)) == 0) Fatal ("Virtual Memory Exhausted"); : Foo = (char *) Malloc (SizeOf * foo); if (foo == 0) Fatal ("Virtual Memory Exhausted"); do not modify the program in order to pass the LINT check. Please do not join anything about Void Mandatory type conversion. There is no null intersteration constant for the type conversion.

Named variables and functions Please use underscores in the name to separate words so that emacs word commands are useful for them. Stick to use lowercase; leave your uppercase letters to macros and enumerations, and prefixed according to a unified convention. For example, you should use the name similar to IGNORE_SPACE_CHANGE_FLAG; do not use the name similar to IcantReadThis. The variable used to indicate whether a command line option is given should be named after the option meaning, not after the option character. A note should explain the precise meaning of the option, but also the letters of the option. For example, / * ignore changes in horizontal white, * / int ignore_space_change_flag; when you need to define the name for constant integer values, use ENUM instead of '#define'. GDB knows the enumeration. Use 14 characters or less than 14 characters to avoid problems in system v on System V without reason. Many existing GNU tools using non-standard feature provide many convenient extensions on a compatible UNIX tool. Do these extensions when implementing your program is a problem that is difficult to answer. On the one hand, the use of extensions can make the program be clear. On the other hand, people cannot create programs unless people can get other GNU tools. This may make the program only work on a fewer machines. For some extensions, the above two options may be easily copened. For example, you can define a function with the "keyword" inline and define the inline into a macro, determine it according to the compiler it is expanded into inline or expands. Generally, if you can complete the task without their situation, the best way to do not use expansion, but if the extension can greatly improve your work, use extensions. One exception to this rule is a large-scale and created program that runs on a large number of different systems (such as EMACS). These programs will be destroyed using GNU extensions. Another exception is the program as part of the compilation itself: This includes anything that must be compiled with other compilers to construct anything in the GNU compilation tool. If they need a GNU compiler, no one can compile them without installing them. This will be bad. Since most of the computer systems have not implemented standard C, standard C is used, so using standard C is equivalent to using GNU extensions, the front considerations apply to it. (Except for those standard features such as Trigraphs, such as Trigraphs - Never use them.) The three-way sequence is provided in the standard C to make up for the shortcomings of the available characters on some terminals. A method of combining a character in place of a special character. All available three-way groups are: "?? =" to "#", "?? /" convert to "/", "?? '" to "^", "?? (" conversion into "[ "," ??) "Convert"] "," ??! "To" | ","? <"Converted into" {","? "" To convert to "}", "?? "Convert" ~ ".

Programs for all programs are dynamically assigned all of the data structures, including variable names, rows, files, and symbols, lengths, and quantity of the length and quantity. In most UNIX tools, "long line is not tipped". This is unacceptable to the GNU tool. Tools that read files should not discard NUL characters, or any unprintable characters, including those greater than 0177. The only wise exception is a tool designed to access interfaces that cannot handle specific types of printers that cannot handle these characters. Error check for return values ​​for each system call unless you know that you want to ignore the error. Include those system error text (from PERROR or it) included in the error message caused by each failed system call, if any, if any, if there is a file name and tool name. It is not enough to give "Cannot Open foo.c" or "stat failed". Check each call to Malloc or Realloc to check if it returns 0. Even when Realloc is small, it is necessary to check its return value; in some systems, the size of the block is always expanded to 2 power. If you apply for fewer space, Realloc may get a different block. In UNIX, if Realloc returns 0, it can destroy the storage block. GNU Realloc does not have this error: if it fails, the original block will not be changed. Assassination assumptions have been revised. If you want to run your program on UNIX, and in this case you don't want to lose memory blocks, you can use GNU Malloc. You must assume that Free will change the content of the released block. Anything you want to get from the block, you must get it before calling Free. Use getopt_long to decode the parameters, unless the syntax of the parameter makes this unreasonable. When the program is written during the static memory, it is explicitly used to initialize it. Keep the C initialization statement for data that will not be changed. Try to avoid accessing the low interface of the unix data structure (such as file directory, UTMP, or kernel memory distribution) because they usually reduce compatibility. If you want to find all the files in the directory, use ReadDir or other advanced interfaces. GNU is compatible to support them. In the default, the GNU system will provide the signal processing function of the BSD and the signal processing function of the POSIX. Therefore, GNU software should use them. The condition that "impossible" is detected in the error is that as long as you exit. No reason to print any messages. These checks indicate that there is a bug exists. Anyone who wants to correct the wrong must read the source code and run the debugger. Therefore, the interpretation of the problem is given by comments in the source code. Related data will be stored in variables, which are easily detected by the debugger, so there is no reason to transfer them anywhere.

Format Error message From the compiler error message should be used: Source-file-name: lineno: Message If there is an appropriate source file exists, the error message from non-interactive program should be used: Program: Source- File-name: Lineno: Message or, if there is no relevant source file, you should use the format: Program: Message In an interactive program (from the program read in the program), the program name is not included in the error message. a little better. Indicates that the program is running should be a prompt or a screen of the screen. (When the same program is running from the source file while running, it is not interactive, it is not interactive, and it is best to print an error message in a non-interactive style.) In the string Message is placed When the program name and / or file name, it should not begin with uppercase letters. In addition, it should not end with the sentence. Error information from interactive programs, as well as other information such as usage, should begin with uppercase letters. But they should not end with the end. The behavior of the library tries to make the library function can be renewable. If they need to perform dynamic memory allocation, at least at least to avoid any non-renewable aspects from Malloc itself. Here is a naming convention for some libraries to avoid conflicts of the name. Select a name prefix for more than two characters for the library. All external functions and variable names should begin with this prefix. Also, in any given library member, only one function or variable should be included. This usually means that each function and variable are placed in a separate source file. One exception is if the two symbols are always used together, so that there is no reasonable program only needs to use one without using another one; then they can be placed in the same file. The name indicating the external symbol of the call point not explained in the document should begin with '_'. They also include a name prefix selected for the library to prevent conflicts that may be generated with other libraries. If you like, they can be placed in the same file with the user call point. You can follow your will use static functions and static variables and they don't need to obey any naming practices.

Transplantation for GNUs In UNIX, "transplantability" often refers to porting to different UNIX versions. For the GNU software, it is second because of their main purpose to run on the GNU core and only run, using the GNU C compiler and compile it by it. The number of varieties of various GNU systems on different CPUs will be as much as variants of Berkeley 4.3 systems on different CPUs. Today all users run the GNU software on the non-GNU system. So it is necessary to support a variety of non-GNU systems; however, it is not particularly important. The easiest way to get portability on a reasonable range is to use AutoConf. Since most procedures need to know about the knowledge of the host has been written by AutoConf, your program is unlikely to know more knowledge than the knowledge that AutoConf can provide. Because the current GNU kernel is not completed, it is difficult to determine that the GNU core will provide those tools. So, assume that you can use anything you can use in 4.3; just avoid using a semi-interior data structure (for example, Directories) where the more advanced alternative (READDIR) is avoided. You can freely assume any reasonable C language standard tools, libraries or kernels, because we will find it to support them in a complete GNU system, regardless of whether we have done this. Some existing kernels or C compilers have no relationships with GNU kernels and C compilers. Another need to worry that the CPY type is different, such as the difference between the word sequence, and alignment. The 16-bit machine may not be supported by the GNU, so it is not necessary to spend any time to consider the possibility of less than 32 digits. You can assume that all pointers have the same format, regardless of what they point to, and they are actually an integer. Not like this in some weird machines, but they are not important; do not waste time for them. In addition, we will eventually put the function prototype in all GNU programs, which will mobilize your program to work even on a weird machine. Because some important machines (including 68000) are high-endian, it is not possible to assume that the address of the integer object is the address of the minimum bit byte (Least-Significant). Therefore, don't make the following mistakes: int C; ... while ((c = getchar ())! = EOF) Write (file_descriptor, & c, 1); you can assume that a megaby memory is reasonable. Unless it can be done at that level, do not cost to reduce memory. If your program creates a complex data structure, store them in the kernel, and give a fatal error when Malloc returns 0. If a program works in accordance with the line and can be used for any input file provided by any user, it should only save only one line in memory, because this is not very difficult and the user will need to be able to operate more than the kernel. Enter the file.

Command Line Interface Standard Do not let the behavior of the tool rely on the name called it. Sometimes you need to connect a tool to a different name, and this will not change its function. Alternatively, you can use the options or compiler options at runtime, or simultaneously use both to select different program behaviors. The guidance of the procedure of the procedure from POSIX is a good idea. The easiest way to do this is to use getOpt to analyze the options. It should be noted that unless special parameters '-', the GNU version of Getopt usually allows options to appear anywhere in the parameter. This is not the provisions of POSIX; it is the expansion of the GNU. Please define the equivalent length name option for Unix style single-character options. We hope to make GNU more friendly in this way. This is easy to do with GNU functions getopt_long. Usually only the file name given by the most ordinary parameters is a good idea; all output files should be given by option (better). Even if you allow the normal parameters as an output file name, you can still try to provide an appropriate option for the output file name. This will bring more consistency to the GNU tool to reduce the characteristics of users need memory. The program should also support the option '--version' for the version number of the output program, and supports an option '--help' for outputting option usage information.

Use TexInfo to make a document for the program. See the TEXINFO manual, hard copy or version of the GNU Emacs Info subsystem. (C-H i). As an example, you can take a look at the existing GNU Texinfo file (for example, the TexInfo file under the 'Man /' directory in the GNU Emacs). The header page of the manual should indicate the version of this manual for the program. The top node of the manual should also contain this information. If the manual is faster than the program, the latter is independent of the program, please explain the version number of the manual in the above two places. The manual should explain that all command line parameters and all commands. The manual should give an example of using them. But don't organize the manual into a list of features. Instead, the document is organized in the manual in a manner in which the user needs to be understood. Note The user may need to achieve, and explain how to complete them. Don't use the Unix MAN manual as a pattern of writing GNU documents; they are not worthwhile to imitate. The manual should have a node called 'Program Invocation' or 'Program Invoke' or 'Invoking Program', where program is the program name of the program, that is, enter that name to run the program in the shell. This node (if it has a sub-node, including child nodes) should explain the command line parameters of the program and how to run it (that is, the type of information will be seen in the Man manual). Templates that contain all options and parameters that can be used in '@example'. Alternatively, add a name that is one of the above modes in some menus. It indicates that the node pointed out by the menu item is created for this, regardless of what the actual name of this node is. There will be an automatic function that allows the user to give the program name and only the part of the manual is required. If a manual illustrates multiple programs, the manual should define such a node for each program you explain. In addition to the manual of the package, the package should also contain a file called 'News', which contains a modification of the user and is worth mentioning. In each new release, add a new entry in front of the file and point out the version for their. Don't delete the original entry; keep them behind the new entries. In this way, users who have upgraded from previous versions can see those new features. If the 'news' file becomes too long, some of the old items can be placed in a file called 'OneWS' and add an explanation to tell the user to refer to 'Onews' at the end of the 'news' file. If you like, you can provide a Manbook while providing the TexInfo manual. However, keep in mind that maintaining the MAN manual requires efforts when you change each program. You spend any time in the Man's manual consumes that you can use the time that contributes more valuable. Therefore, even if the user voluntarily provides the Manbook, you may find that this gift is too trouble and is not worth accepting. Unless you have time, and unless you are willing to undertake full responsibility to maintain it - so that you can handle it completely to him, you may be better. If the volunteers stop maintaining the MAN manual, then there is no need to feel responsible for yourself to bear it; in other volunteers maintain it, the MAN manual may be better. Another way is that if you want the content of the Manbook and the actual situation, it is still useful to make the MAN manual, and a significant statement can be given at the beginning of the MAN manual to explain that you did not maintain it and the Texinfo manual is more authoritative. Also point out how to access the TexInfo document.

转载请注明原文地址:https://www.9cbs.com/read-71574.html

New Post(0)