📄 standards.texi
字号:
@item recursiveUsed in @code{chgrp}, @code{chown}, @code{cp}, @code{ls}, @code{diff},and @code{rm}.@item reference-limitUsed in @code{makeinfo}.@item references@samp{-r} in @code{ptx}.@item regex@samp{-r} in @code{tac} and @code{etags}.@item release@samp{-r} in @code{uname}.@item reload-state@samp{-R} in @code{m4}.@item relocation@samp{-r} in @code{objdump}.@item rename@samp{-r} in @code{cpio}.@item replace@samp{-i} in @code{xargs}.@item report-identical-files@samp{-s} in @code{diff}.@item reset-access-time@samp{-a} in @code{cpio}.@item reverse@samp{-r} in @code{ls} and @code{nm}.@item reversed-ed@samp{-f} in @code{diff}.@item right-side-defs@samp{-R} in @code{ptx}.@item same-order@samp{-s} in @code{tar}.@item same-permissions@samp{-p} in @code{tar}.@item save@samp{-g} in @code{stty}.@item seUsed in GDB.@item sentence-regexp@samp{-S} in @code{ptx}.@item separate-dirs@samp{-S} in @code{du}.@item separator@samp{-s} in @code{tac}.@item sequenceUsed by @code{recode} to chose files or pipes for sequencing passes.@item shell@samp{-s} in @code{su}.@item show-all@samp{-A} in @code{cat}.@item show-c-function@samp{-p} in @code{diff}.@item show-ends@samp{-E} in @code{cat}.@item show-function-line@samp{-F} in @code{diff}.@item show-tabs@samp{-T} in @code{cat}.@item silentUsed in many programs to inhibit the usual output.Every program accepting@samp{--silent} should accept @samp{--quiet} as a synonym.@item size@samp{-s} in @code{ls}.@item socketSpecify a file descriptor for a network server to use for its socket,instead of opening and binding a new socket. This provides a way torun, in a nonpriveledged process, a server that normally needs areserved port number.@item sortUsed in @code{ls}.@item source@samp{-W source} in @code{gawk}.@item sparse@samp{-S} in @code{tar}.@item speed-large-files@samp{-H} in @code{diff}.@item split-at@samp{-E} in @code{unshar}.@item split-size-limit@samp{-L} in @code{shar}.@item squeeze-blank@samp{-s} in @code{cat}.@item start-delete@samp{-w} in @code{wdiff}.@item start-insert@samp{-y} in @code{wdiff}.@item starting-fileUsed in @code{tar} and @code{diff} to specify which file withina directory to start processing with.@item statistics@samp{-s} in @code{wdiff}.@item stdin-file-list@samp{-S} in @code{shar}.@item stop@samp{-S} in Make.@item strict@samp{-s} in @code{recode}.@item strip@samp{-s} in @code{install}.@item strip-all@samp{-s} in @code{strip}.@item strip-debug@samp{-S} in @code{strip}.@item submitter@samp{-s} in @code{shar}.@item suffix@samp{-S} in @code{cp}, @code{ln}, @code{mv}.@item suffix-format@samp{-b} in @code{csplit}.@item sum@samp{-s} in @code{gprof}.@item summarize@samp{-s} in @code{du}.@item symbolic@samp{-s} in @code{ln}.@item symbolsUsed in GDB and @code{objdump}.@item synclines@samp{-s} in @code{m4}.@item sysname@samp{-s} in @code{uname}.@item tabs@samp{-t} in @code{expand} and @code{unexpand}.@item tabsize@samp{-T} in @code{ls}.@item terminal@samp{-T} in @code{tput} and @code{ul}.@samp{-t} in @code{wdiff}.@item text@samp{-a} in @code{diff}.@item text-files@samp{-T} in @code{shar}.@item timeUsed in @code{ls} and @code{touch}.@item timeoutSpecify how long to wait before giving up on some operation.@item to-stdout@samp{-O} in @code{tar}.@item total@samp{-c} in @code{du}.@item touch@samp{-t} in Make, @code{ranlib}, and @code{recode}.@item trace@samp{-t} in @code{m4}.@item traditional@samp{-t} in @code{hello};@samp{-W traditional} in @code{gawk};@samp{-G} in @code{ed}, @code{m4}, and @code{ptx}.@item ttyUsed in GDB.@item typedefs@samp{-t} in @code{ctags}.@item typedefs-and-c++@samp{-T} in @code{ctags}.@item typeset-mode@samp{-t} in @code{ptx}.@item uncompress@samp{-z} in @code{tar}.@item unconditional@samp{-u} in @code{cpio}.@item undefine@samp{-U} in @code{m4}.@item undefined-only@samp{-u} in @code{nm}.@item update@samp{-u} in @code{cp}, @code{ctags}, @code{mv}, @code{tar}.@item usageUsed in @code{gawk}; same as @samp{--help}.@item uuencode@samp{-B} in @code{shar}.@item vanilla-operation@samp{-V} in @code{shar}.@item verbosePrint more information about progress. Many programs support this.@item verify@samp{-W} in @code{tar}.@item versionPrint the version number.@item version-control@samp{-V} in @code{cp}, @code{ln}, @code{mv}.@item vgrind@samp{-v} in @code{ctags}.@item volume@samp{-V} in @code{tar}.@item what-if@samp{-W} in Make.@item whole-size-limit@samp{-l} in @code{shar}.@item width@samp{-w} in @code{ls} and @code{ptx}.@item word-regexp@samp{-W} in @code{ptx}.@item writable@samp{-T} in @code{who}.@item zeros@samp{-z} in @code{gprof}.@end table@node Memory Usage@section Memory Usage@cindex memory usageIf a program typically uses just a few meg of memory, don't bother making anyeffort to reduce memory usage. For example, if it is impractical forother reasons to operate on files more than a few meg long, it isreasonable to read entire input files into core to operate on them.However, for programs such as @code{cat} or @code{tail}, that canusefully operate on very large files, it is important to avoid using atechnique that would artificially limit the size of files it can handle.If a program works by lines and could be applied to arbitraryuser-supplied input files, it should keep only a line in memory, becausethis is not very hard and users will want to be able to operate on inputfiles that are bigger than will fit in core all at once.If your program creates complicated data structures, just make them incore and give a fatal error if @code{malloc} returns zero.@node File Usage@section File Usage@cindex file usagePrograms should be prepared to operate when @file{/usr} and @file{/etc}are read-only file systems. Thus, if the program manages log files,lock files, backup files, score files, or any other files which aremodified for internal purposes, these files should not be stored in@file{/usr} or @file{/etc}.There are two exceptions. @file{/etc} is used to store systemconfiguration information; it is reasonable for a program to modifyfiles in @file{/etc} when its job is to update the system configuration.Also, if the user explicitly asks to modify one file in a directory, itis reasonable for the program to store other files in the samedirectory.@node Writing C@chapter Making The Best Use of CThis chapter provides advice on how best to use the C languagewhen writing GNU software.@menu* Formatting:: Formatting Your Source Code* Comments:: Commenting Your Work* Syntactic Conventions:: Clean Use of C Constructs* Names:: Naming Variables, Functions, and Files* System Portability:: Portability between different operating systems* CPU Portability:: Supporting the range of CPU types* System Functions:: Portability and ``standard'' library functions* Internationalization:: Techniques for internationalization* Character Set:: Use ASCII by default.* Quote Characters:: Use `...' in the C locale.* Mmap:: How you can safely use @code{mmap}.@end menu@node Formatting@section Formatting Your Source Code@cindex formatting source code@cindex open brace@cindex braces, in C sourceIt is important to put the open-brace that starts the body of a Cfunction in column one, and avoid putting any other open-brace oropen-parenthesis or open-bracket in column one. Several tools lookfor open-braces in column one to find the beginnings of C functions.These tools will not work on code not formatted that way.It is also important for function definitions to start the name of thefunction in column one. This helps people to search for functiondefinitions, and may also help certain tools recognize them. Thus,using Standard C syntax, the format is this:@examplestatic char *concat (char *s1, char *s2)@{ @dots{}@}@end example@noindentor, if you want to use traditional C syntax, format the definition likethis:@examplestatic char *concat (s1, s2) /* Name starts in column one here */ char *s1, *s2;@{ /* Open brace in column one here */ @dots{}@}@end exampleIn Standard C, if the arguments don't fit nicely on one line,split it like this:@exampleintlots_of_args (int an_integer, long a_long, short a_short, double a_double, float a_float)@dots{}@end exampleThe rest of this section gives our recommendations for other aspects ofC formatting style, which is also the default style of the @code{indent}program in version 1.2 and newer. It corresponds to the options@smallexample-nbad -bap -nbc -bbo -bl -bli2 -bls -ncdb -nce -cp1 -cs -di2-ndj -nfc1 -nfca -hnl -i2 -ip5 -lp -pcs -psl -nsc -nsob@end smallexampleWe don't think of these recommendations as requirements, because itcauses no problems for users if two different programs have differentformatting styles.But whatever style you use, please use it consistently, since a mixtureof styles within one program tends to look ugly. If you arecontributing changes to an existing program, please follow the style ofthat program.For the body of the function, our recommended style looks like this:@exampleif (x < foo (y, z)) haha = bar[4] + 5;else @{ while (z) @{ haha += foo (z, z); z--; @} return ++x + bar (); @}@end example@cindex spaces before open-parenWe find it easier to read a program when it has spaces before theopen-parentheses and after the commas. Especially after the commas.When you split an expression into multiple lines, split itbefore an operator, not after one. Here is the right way:@cindex expressions, splitting@exampleif (foo_this_is_long && bar > win (x, y, z) && remaining_condition)@end exampleTry to avoid having two operators of different precedence at the samelevel of indentation. For example, don't write this:@examplemode = (inmode[j] == VOIDmode || GET_MODE_SIZE (outmode[j]) > GET_MODE_SIZE (inmode[j]) ? outmode[j] : inmode[j]);@end exampleInstead, use extra parentheses so that the indentation shows the nesting:@examplemode = ((inmode[j] == VOIDmode || (GET_MODE_SIZE (outmode[j]) > GET_MODE_SIZE (inmode[j]))) ? outmo
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -