Nan*_*iao 9 c++ pointers language-lawyer
我读这个帖子这是关系到char和byte,并遇到了下面的话:
一个
int*仍然可以被实现为单个硬件指针,因为C++允许sizeof(char*) != sizeof(int*).
如何理解'C++允许sizeof(char*) != sizeof(int*)'?
In short, the standard doesn't guarantee it, the result is implementation-defined.
\n\nFrom the standard about sizeof ($5.3.3/1 Sizeof [expr.sizeof])
\n\n\nThe sizeof operator yields the number of bytes in the object\n representation of its operand.
\n
and pointer is compound type ($3.9.2/1.3 Compound types [basic.compound])
\n\n\n\n\npointers to void or objects or functions (including static members of\n classes) of a given type, 8.3.1;
\n
and ($3.9.2/3 Compound types [basic.compound])
\n\n\n\n\nThe value representation of pointer types is implementation-defined.
\n
even though ($3.9.2/3 Compound types [basic.compound])
\n\n\n\n\nPointers to layout-compatible types shall have the same value\n representation and alignment requirements (3.11).
\n
but char and int don't need to have the same value representation. The starndard only says ($3.9.1/2 Fundamental types [basic.fundamental])
\n\n\nThere are five standard signed integer types : \xe2\x80\x9csigned char\xe2\x80\x9d, \xe2\x80\x9cshort\n int\xe2\x80\x9d, \xe2\x80\x9cint\xe2\x80\x9d, \xe2\x80\x9clong int\xe2\x80\x9d, and \xe2\x80\x9clong long int\xe2\x80\x9d. In this list, each type\n provides at least as much storage as those preceding it in the list.
\n
和($3.9.1/3 基本类型 [basic.fundamental])等。
\n\n\n\n每个有符号整数类型都与其对应的无符号整数类型具有相同的对象表示形式。
\n
| 归档时间: |
|
| 查看次数: |
524 次 |
| 最近记录: |