C 語言規格書閱讀
object
- 3.14 提到
object
是在執行環境中資料儲存的區域,其內容可以表示值
type
- 6.2.5 Types are partitioned into object types (types that fully describe objects), function types (types that describe functions), and incomplete types (types that describe objects but lack information needed to determine their sizes).
- 6.2.5 Array, function, and pointer types are collectively called derived declarator types. A declarator type derivation from a type T is the construction of a derived declarator type from T by the application of an array-type, a function-type, or a pointer-type derivation to T.
- 6.2.5 Arithmetic types and pointer types are collectively called scalar types. Array and structure types are collectively called aggregate types.
lvalue
- 6.3.2.1 提到
lvalue
(locator value) 是一個具有 object type
或是除 void
之外的 incomplete type
的表達式
- lvalue is an identifier of an object
- If E is a unary expression that is a pointer to an object, *E is an lvalue that designates the object to which E points
- rvalue is in this International Standard described as the value of an expression
- 6.2.5 incomplete types : types that describe objects but lack information needed to determine their sizes.
NULL
- 6.3.2.3 An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant.
void*
- 6.2.5 A pointer to void shall have the same representation and alignment requirements as a pointer to a character type
- The same representation and alignment requirements are meant to imply interchangeability as arguments to functions, return values from functions, and members of unions.
- void * 與 char * 可以互換
- void * 的設計,導致開發者必須透過 explicit (顯式) 或強制轉型,才能存取最終的 object,否則就會丟出編譯器的錯誤訊息,從而避免危險的指標操作
Function designator
- 6.3.2.1.4 A function designator is an expression that has function type. Except when it is the operand of the sizeof operator or the unary & operator, a function designator with type ‘‘function returning type’’ is converted to an expression that has type ‘‘pointer to function returning type’’
Because this conversion does not occur, the operand of the sizeof operator remains a function designator and violates the constraint in 6.5.3.4.
-
6.5.3.2.1 The operand of the unary & operator shall be either a function designator, the result of a [] or unary * operator, or an lvalue that designates an object that is not a bit-field and is not declared with the register storage-class specifier.
-
6.5.3.2.4 The unary * operator denotes indirection.
- If the operand points to a function, the result is a function designator; if it points to an object, the result is an lvalue designating the object.
- If the operand has type ‘‘pointer to type’’, the result has type ‘‘type’’.
- If an invalid value has been assigned to the pointer, the behavior of the unary * operator is undefined.