下载  >  开发技术  >  C  > gnu c manual GNU C编译器的手册文档

gnu c manual GNU C编译器的手册文档 评分:

GNU C编译器的实现参考,对于GNU C编译器提供的基础设施有详细描述
Table of Contents Preface Credits 1 Lexical elements 1.1 Identifiers 1.2K 1.3 Constant 1.3.1 Integer constants 3 3.2 Charactcr Constants 3 1.3.3 Real Number Constants 1.3. 4 String Constants 1.4 Operators 6 1.5 1.6 White Spa 6 2 Data Types 。·垂 2.1 Primitive Data Types 2.1.1 Integer Types 2.1.2 Real Number Types ·.,::.:.:.·· 9 2. 1.3 Complex Number Types................. 10 2.1.3.1 Standard complex Number Types 10 2. 1.3.2 GNU Extensions for Complcx Number TypCs.... 11 2.2 Enumerations 2.2 1 Defining enumerations ,,,,,,,,,11 2.2.2 Declaring Enumerations 12 2.3 Unions 12 2.3. 1 Defining Unions ·· 12 2.3.2 Declaring Union Variables 13 2.3.2.1 Declaring Union Variables at Definition 13 2.3.2.2 Declaring Union Variables After Definition . .........13 2.3.2.3 Initializing Union Members 13 2.3. 3 Accessing Union Members 14 2.3.4 Size of unions 14 2.4St Fractures 2.4.1 Defining Structures 2.4.2 Declaring Structure Variables 15 2.4.2.2 Declaring Structure Variables After Definitig....15 2.1.2.1 Declaring Structure Variables at Definition ..16 2.1.2.3 Initializing Structure Members 16 2.4.3 Accessing Structure Members 17 2.4.4 Bit fields 2.4.5 Size of structures 2.5 Arrays 2.5.1 Declaring Arrays 19 2.5.2 Initializing Arrays 20 5. 3 Accessing Array Elements ∴...21 2.5.4 Multidimensional arrays 21 2.5.5 Arrays as Strings 21 2.5.6 Arrays of unions ·鲁鲁 22 2.5.7 Arrays of Structures 23 2.6 Pointers 23 2.6. 1 Declaring Pc 23 2.6.2 Initializing point 24 2.6.3 Pointers to unions 24 2.6.4 Pointers to structures 25 2.7 Incomplete Typcs..…….,25 vpe Qualifiers b 2.9S1 fi S Spccincrs 26 2.10 Renaming Types 27 3 Expressions and Operators 28 3.1 Expressions 28 3.2 Assignment Operat 8 3.3 Incrementing and decrementing ··: 29 3.1 Arithmetic Oper 30 5 Conplex Conjugation .32 3.6 Comparison Operators 32 3.7 Logical Operators 33 3. 8 Bit Shifting .33 3.9 Bitwise Logical Opera 34 3.10 Pointer Opcrators .35 3.11 The sizeof operator 35 3.12 Type Cast 36 3. 13 Array Subscripts 37 3.14 Function Calls as expressions ··: 37 3.15 The Comma Operator 37 3.16 Member Access Expressions 38 3.17 Conditional Expressions 38 3.18 Statements and Declarations in Expressions 39 3.19 Operator Precedence 40 3.20 Order of evaluation 着鲁普 41 3.20.1 Side effects 41 3.20.2 Sequence Points 41 3.20.3 Sequence Points Constrain expressions 412 3.20.4 Sequence Poinls and signal Delivery 44 4 Statements 45 4.1 Labels 45 4.2 Expression Statements 415 4.3 The if Statement 45 4.1 The switch Statement ·.····. .17 4.5 The while statemer 48 4.6 The do Statement 49 4.7 The for statement .,49 4.8 Blocks 51 4.9 The Nulll Statement 52 4.10 The goto Statement 52 4.11 The break Statement 53 4.12 The continue Statement ∴..53 4.13 The return Statement ·: 4 4.14 The typedef Statement 54 5 Functions 56 5.1 Function declarations 56 5.2 Function Definitions 56 5.3 Calling Functions 57 5.4 Function parameters 58 5.5 Variable Length Parameter Lists 59 6 Ca. ing Functions Through Function Point 60 5.7 Thc main Function 61 5.8 Recursive Functions 62 5.9 Static Functions 62 5.10 Nested Functions 63 6 Program Structure and Scope 64 6.1 Program Structure 64 6.2 Scope 64 7 A Sample Program 66 7.1he110.C 66 7.2 system. h 69 Appendix a OverFlow 71 A,1 B of Integer Overflo 71 A2 Examples of Code Assuming Wraparound Overflow ..71 A 3 Optimizations That Break Wraparound Arithmetic 73 A 4 PracTical Advice for Signed Overflow Issues A.5 Signed Integer Division and Integer Overfow GNU Free documentation license 76 alex 84 Preface Preface This is a reference manual for the c programming language as implemented by the gnu Compiler Collection(GCC). Specifically, this manual aims to document ·The1989 ANSI C Standard, commonly known as“C89” e The 1999 ISoC standard. commonly known asC 99, to the extent that c99 is implemented by gcc e The current state of gnu extensions to standard c This manual describes C89 as its baseline. C99 features and gnU extensions are explicitly labeled as such By default, GCC will compile code as C89 plus GNU-specific extensions. Much of C99 is supported; once full support is available, the default compilation dialect will be C9 9 plus GNU-Specific extensions.(Some of the GNU extensions to C89 ended up, sometimes slightly modified, as standard language features in C99. The C language includes a set of preprocessor directives, which are used for things such as macro lext replacement, conditional compilalion, and file inclusiOn. Although normally described in a C language manual, the gnu c preprocessor has been thoroughl documented in The C Preprocessor, a separate manual which covers preprocessing for C C++, and Objective-C programs, so it is not included here Credits Thanks to everyone who has helped with editing proofreading, ideas, typesetting, and administrivia, including: Diego Andres Alvarez marin, Nelson H. F. Beebe, Karl berry Robert Chasscll Hanfeng Chen. Mark dc Volld. Antonio diaz Diaz. dinc. Andrcas Focrstcr Denver Gingerich, Lisa Goldstein, Robert Hansen, Jean-Christophe Helary, Mogens Het. sholm, Tcddy Hogcborn, Joc Humphries, J. Wron Hunt, Dutch Ingraham, Adam Johansen Vladimir Kadlec, Benjamin Kagia, Dright Kayorent, Sugun Kedambadi, Felix Lee, Bjorn Liencres, Steve morningthunder, Aljosha Papsch, Matthew Plant, Jonathan Sisti, Richard Stallman, J. Otto Tennant, Ole Tetlie, Keith Thompson, T.F. Torrey James Youngman and Steve Zachar. Trevis rothwell serves as project maintainer and, along with James Youngman. wrote the bulk of the text Some example programs are based on algorithms in Donald Knuth's The Art of Com- paler Programining Please send bug reports and suggesTions to gnu-c-manualognu org Chapter 1: Lexical Elements 1 Lexical elements This chapter describes the lexical elements that make up C source code after preprocessing These elements are called tokens. There are five types of tokens: keywords, identifiers constants, operators, and separators. White space, sometimes required to separate tokens, is also described in this chapter 1.1 Identifiers Identifiers are sequences of characters used for naming variables, functions, new data types and preprocessor macros. You can include letters, decimal digits, and the underscore char acter‘’ in identifiers The first character of an identifier cannot be a digit Lowercase letters and uppercase letters are distinct, such that foo and Fo0 are two different identifiers iix when using GNU extensions, you can also include the dollar sign character ' $ in iden- 1.2 Keywords Keywords are special identifiers reserved for use as part of the programming language itself You cannot use them for any other purpose Here is a list of key words recognized by ANSI C89 auto break case char const continue default do double else enum extern float for goto if int long register return short signed sizeof static struct switch typedef union unsigned void volatile while Iso C99 adds the following key words inline__Bool-Complex _Imaginary and gnu extensions add these keyword FUNCTION____PRETTY-FUNCTION__--alignof --alignof____asm asm attribute attribute builtin_offsetof __builtin_va_arg complex __complex____const -_extension func imag -_imag inline inline label mull 1 real restrict1 estrid七 signed __signed thread typeof volatile volatile In both Iso C99 and C89 with gnu extensions, the following is also recognized as a keyword restric七 1.3 Constants a constant is a literal numeric or character value such as 5 or 'm.all constants are of a particular data type; you can use type casting to explicitly specify the type of a constant or let the compiler use the default type based on the value of the constant Chapter 1: Lexical Elements 1.3.1 Integer Constants An integer constant is a sequence of digits, with an optional prefix to denote a number base If the sequence of digits is preceded by Ox or OX(zero x or zero X, then the constant is considered to be hexadecimal(base 16). Hexadecimal values may use the digits from 0 to 9, as well as the letters a to f and a to F. Here are some examples 0x2f 0x88 OxAB43 OxAbCd 0x1 If the first digit is 0(zero), and the next character is not x'or'X', then the constant is cOnsidered to be octal(base 8). Octal values nay only use the digits [rom 0 lo 7; 8 and 9 are not allowed. Here are some examples 057 012 03 0241 In all other cases, the sequence of digits is assumed to be decimal(base 10). Decimal values may use the digits from 0 to 9. Here are some examples 459 23901 8 12 There are various integer data types, for short integers, long integers, signed integers and unsigned integers. You can force an integer constant to be of a long and or unsigned integer type by appending a sequence of one or more letters to the end of the constant uU1L Unsigned integer type Long integer type For example, 45U is an unsigned int constant. You can also combine letters: 45UL is an unsigned long int constant.(The letters may be used in any order. Both Iso C99 and gNU C extensions add the integer types longlong int and unsigned long long int. You can use two 'L's to get a long long int constant; add a'U to that and you have an unsigned long long int constant. For example: 45ULL 1.3.2 Character Constants a character constant is usually a single character enclosed within single quotation marks such as'Q'. A character constant is of type int by default ome characters, such as the single quotation mark character itself, cannot be represented using only one character. To represent such characters, there are several "escape sequences that you can use Backslash character Chapter 1: Lexical Elements Question mark character Single quotation mark Double quotation mark a Audible alert b Backspace character <ESC> character. (This is a GNU extension \f Form feed n Newline character Carriage rcturn t Horizontal tab Vertical tab \o, oo, ooo Octal number \xh, xhh, \ xhhh, Hexadecimal number To use any of these escape sequences, enclose the sequence in single quotes, and treat it as if it were any other character. For example, the letter m is ' and the newline character Is>\n The octal numbcr escape scqucncc is the backslash charactor followcd by onc. two, or three octal digits(0 to 7). For example, 101 is the octal equivalent of 65, which is the ASCII character A,. Thus, the character constant )\101, is the same as the character constant A The hexadecimal escape sequence is the backslash character, followed by x and an unl- limited number of hexadecimal digits(0 to 9, and a to f or a to F) While the length of possible hexadecimal digit strings is unlimited, the number of char- acter constants in any given character set is not.(The much-used extended ASCIi character set, for example, has only 256 characters in it. If you try to use a hexadecimal value that is outside the range of characters, you will get a compile-time error 1.3.3 Real number constants A real number constant is a value that represents a fractional (Hoating point) number. It consists of a sequence of digits which represents the integer(or"whole")part of the number, a decimal point, and a sequence of digits which represents the fractional part Either the integer part or the fractional part may be omitted, but not both. Here are some examples Chapter 1: Lexical Elements double a, b, c, d,e,f 7 (In the third assignment statement, the integer constant 4 is automatically converted from an integer value to a double value Rcal number constants can also be followcd by e or E, and an integer exponent. Tho exponent can be eit, her positive or negative double x, y; =5e2;/*xis5*100,or500.0 y=5e-2;/*yis5*(1/100),or0.05.*/ You can append a letter to the end of a real number constant to cause it to be of a particular type. If you append the letter F (or f) to a real number constant, then its type is float. If you append the letter L(or 1), then its type is long double. If you do not append any letters, then its type is double 1.3.4 String Constants a string constant is a sequence of zero or more characters. digits, and escape sequences enclosed within double quotation marks. A string constant is of type"array of characters All string constants contain a null termination character (\0)as their last character. Strings character lets string-processing functions know where the string ends@ are stored as arrays of characters, with no inherent size attribute. The null termination Adjacent string constants are concatenated(combined) into one string with the null termination character added to lle end of the final concatenated string ella string cannot contain double quotation marks, as double quotation marks are used to enclose the string To include the double quotation mark character in a string, use the cscapc scqucncc. You can usc any of the cscapc scqucnccs that can be uscd as charactor constants in strings. Here are some example of string constants /* This is a single string constant. * Tutti frutti ice cream /* These string constants will be concatenated, same as above. * tutti l ll ice cream /* This one uses two escape sequences. * l\"hello, world!\"

...展开详情
2017-09-28 上传 大小:550KB
举报 收藏
分享