§6.2.5 #12 An array type of unknown size is an incomplete type.
§6.5.3.4 The sizeof operator The sizeof operator shall not be applied to an expression that has function type or an incomplete type.
但是標準給出了一個例外
§6.7.2.1 第16點 As a special case, the last element of a structure with more than one named member may have an incomplete array type; this is called a flexible array member. … the size of the structure shall be equal to the offset of the last element of an otherwise identical structure that replaces the flexible array member with an array of unspecified length
zero length array事實上是gcc的extension。標準C不允許zero length array
§6.7.5.2 Array declarators If the expression is a constant expression, it shall have a value greater than zero. The element type shall not be an incomplete or function type.
Alice挑了一個數字a 計算出 A=g^a mod p,然後將A數字給Bob Bob挑了一個數字b 計算出 B=g^b mod p,然後將B數字給Alice Alice將拿到的B 計算出 K1=B^a mod p Bob將拿到的A 計算出 K2=A^b mod p 事實上 K1 = K2 亦即他們已經協商出同一把密鑰了
第三者可能得到的資訊是 p, g, A, B,但是沒辦法算出K 而a則是只有Alice知道,b則是只有Bob知道
以下說明 K1=K2
g^a = M * p + A A = g^a – M * p A^b = (g^a – M * p)^b K1 = A^b mod p = (g^a – M * p)^b mod p = g^a^b mod p (二項式展開後只有第一項不整除)
g^b = M’ * p + B B = g^b – M’ * p B^a = (g^b – M’ * p)^a K2 = B^a mod p = (g^b – M’ * p)^a mod p = g^b^a mod p
上面的紅框是C99新增的keyword,_Bool定義成_Bool而不是bool,主要的原因是在C89的標準中,對於reserved identifier是用 底線+大寫字母開頭 或是 雙底線。提供了後續標準新增的關鍵字避免使用上與使用者衝突。另外在標準中提到 Implementation-defined keywords shall have the form of an identifier reserved for any use as described in 7.1.3. 也是同樣的理由
6.4.2.1 An identifier is a sequence of nondigit characters (including the underscore _, the lowercase and uppercase Latin letters, and other characters) and digits.
C99也支援universal-character-name \u or \U開頭的UCN來作為identifier的字元(可以在identifier開頭) \u接4個hex \U接8個hex
當然也考慮了上面提到的不能digit開頭的限制
Each universal character name in an identifier shall designate a character whose encoding in ISO/IEC 10646 falls into one of the ranges specified in annex D.59) The initial character shall not be a universal character name designating a digit.
6.2.1 An identifier can denote an object; a function; a tag or a member of a structure, union, or enumeration; a typedef name; a label name; a macro name; or a macro parameter
Because the controlling constant expression is evaluated during translation phase 4, all identifiers either are or are not macro names — there simply are no keywords, enumeration constants, etc
6.4.2.1 When preprocessing tokens are converted to tokens during translation phase 7, if a preprocessing token could be converted to either a keyword or an identifier, it is converted to a keyword
這段主要是說在preprocessing token階段,沒有keyword概念(可參看上面的6.4 Lexical elements Syntax),所以tokenize時標記的會是identifier,可是到phase 7時,會轉成token,這時候就會區分要算在token的keyword還是identifier
Expressions that are not evaluated do not access objects.
3.2 alignment
alignment requirement that objects of a particular type be located on storage boundaries with addresses that are particular multiples of a byte address
這邊alignment指的是特定型態object的位址,例如word boundary(address divisible by 4 or 8), alignment requirement這部分是跟機器架構有關,也跟指令有關。 x86大部分的指令data access資料的位址不一定要alignment,如果沒有alignment在boundary,存取效率會比較差,但例如i386的__float128就要求一定要對齊16 byte boundary
The C source file is processed by the compiler as if the following phases take place, in this exact order. Actual implementation may combine these actions or process them differently as long as the behavior is the same.
這邊提到 phase of translation只要求compiler實現時表現的行為與這裡描述的步驟等價即可。
phase 1 主要是做character set轉換,和轉換斷行符<EOL>
Physical source file multibyte characters are mapped, in an implementation defined manner, ① to the source character set(introducing ② new-line characters for end-of-line indicators) if necessary. ③ Trigraph sequences are replaced by corresponding single-character internal representations.
其中提到source character set指的是如何解讀source file(encoding) ,source character set在標準裡5.2.1有描述:
Two sets of characters and their associated collating sequences shall be defined: the set in which source files are written (the source character set), and the set interpreted in the execution environment (the execution character set).
對比C++的phase 1是轉成basic source character&UCN:節錄 https://en.cppreference.com/w/cpp/language/translation_phases Any source file character that cannot be mapped to a character in the basic source character set is replaced by its universal character name (escaped with \u or \U) or by some implementation-defined form that is handled equivalently.
phase 1除了source character set mapping外,另外也會將<EOL>換成<LF>,所以在後續的phase,會提到new-line character,是來自於此步驟。
phase 2 line splicing 去行尾的 \ 來做拼接
Each instance of a backslash character (\) immediately followed by a new-line character is deleted, splicing physical source lines to form logical source lines 註: 這裡的new-line character就是從第一步<EOL>轉過來的
The preprocessor treatment of escaped newlines is more relaxed than that specified by the C90 standard, which requires the newline to immediately follow a backslash.)
A source file that is not empty shall end in a new-line character, which shall not be immediately preceded by a backslash character before any such splicing takes place
A preprocessing token is the minimal lexical element of the language in translation phases 3 through 6.
指的是compile(phase 7)前 preprocessor看到的token
Each comment is replaced by one space character. New-line characters are retained. Whether each nonempty sequence of white-space characters other than new-line is retained or replaced by one space character is implementation-defined
phase 5 mapping to execution character set mapping
Each source character set member and escape sequence in character constants and string literals is converted to the corresponding member of the execution character set;
Adjacent string literal tokens are concatenated 單純string literal連接,這一步已經是execution character set 。將”str1″ “str2” 連成 “str1str2”
phase 7 compile
Each preprocessing token is converted into a token. The resulting tokens are syntactically and semantically analyzed and translated as a translation unit.
這一步就是compile,compile成translation unit
phase 8 link
All external object and function references are resolved. Library components are linked to satisfy external references to functions and objects not defined in the current translation. All such translator output is collected into a program image which contains information needed for execution in its execution environment