c**********e 发帖数: 2007 | 1 在64 bit的机器上,指针的大小是不是 8 byte? |
l*********s 发帖数: 5409 | |
c**********e 发帖数: 2007 | 3 看来标准答案还是“依赖于系统”。虽然俺用的 unix上 windows上都是4字节。 |
O*******d 发帖数: 20343 | 4 64bit的windows上,
int d = ptr1 - ptr2是错误的。 |
b***i 发帖数: 3043 | |
c******e 发帖数: 545 | 6 windows x64, native 64bit program: 8-byte |
b***i 发帖数: 3043 | 7 http://blogs.msdn.com/b/oldnewthing/archive/2004/02/09/70002.as
【在 c******e 的大作中提到】 : windows x64, native 64bit program: 8-byte
|
d*****y 发帖数: 205 | 8 pointer 本身size这跟寻址方式有关
即便是32位系统, 全指针也要48位(16位段+32位偏移),只不过在除了驱动程序和内
核外一般用不到就是了。
【在 c**********e 的大作中提到】 : 在64 bit的机器上,指针的大小是不是 8 byte?
|
w*********u 发帖数: 392 | 9 这个看着还靠垫儿普
需要知道指针大小的程序,如果hardcode,肯定就是一个bug
【在 d*****y 的大作中提到】 : pointer 本身size这跟寻址方式有关 : 即便是32位系统, 全指针也要48位(16位段+32位偏移),只不过在除了驱动程序和内 : 核外一般用不到就是了。
|
g***l 发帖数: 2753 | 10 ptrdiff_t 和 size_t 不就是用来解决这个指针大小问题的吗?
【在 w*********u 的大作中提到】 : 这个看着还靠垫儿普 : 需要知道指针大小的程序,如果hardcode,肯定就是一个bug
|
|
|
E6 发帖数: 105 | 11 ?????
这个和全指针什么关系? 段+偏移难道不是系统自己算的?怎么能算是pointer的SIZE?
【在 d*****y 的大作中提到】 : pointer 本身size这跟寻址方式有关 : 即便是32位系统, 全指针也要48位(16位段+32位偏移),只不过在除了驱动程序和内 : 核外一般用不到就是了。
|
E6 发帖数: 105 | 12 而且哪个偏移+段地址的算法好像楼上说的也不对.
【在 E6 的大作中提到】 : ????? : 这个和全指针什么关系? 段+偏移难道不是系统自己算的?怎么能算是pointer的SIZE?
|
c*********e 发帖数: 16335 | 13 size_t到底是指什么?unsigned long long?
【在 g***l 的大作中提到】 : ptrdiff_t 和 size_t 不就是用来解决这个指针大小问题的吗?
|
E6 发帖数: 105 | 14 size_t是typedef吧?就是dependent on OS
【在 c*********e 的大作中提到】 : size_t到底是指什么?unsigned long long?
|
c*********e 发帖数: 16335 | 15 恩,书上是这么说的,听着非常灵活,非常玄的感觉.
【在 E6 的大作中提到】 : size_t是typedef吧?就是dependent on OS
|
t****t 发帖数: 6806 | 16 According to standard 18.2:
size_t is implementation-defined *unsigned* integer type, large enough to
contain the *size in bytes* of any object.
ptrdiff_t is implementation-defined *signed* integer type that can hold the
difference of two subscripts in an array object.
So, basically by definition, size_t is the result type of "sizeof" operator;
ptrdiff_t is the result type of "-" operator when the operand are pointers.
However, sizeof ptrdiff_t is NOT necessary sizeof pointer. sizeof pointer is
roughly (read: less than or equal to) sizeof intptr_t or sizeof uintptr_t.
These two types are introduced in C99 and adopted in C++11, and are optional
in both standards.
【在 c*********e 的大作中提到】 : 恩,书上是这么说的,听着非常灵活,非常玄的感觉.
|