由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - is size_t recommended for 64-bit windows porting?
相关主题
pointer overflowQuestion about data member offset
C++ 菜鸟问一个关于template 的问题。C++中size_type怎么处理?
说起来上次谁推荐的memmove作面试题来着What is size_t mean in C?
C 中的typedef 一问狠偷懒狠偷懒的一个测试
Java的POD比C++干净很多std::size_t的麻烦
请教一个C的问题class with a pointer member
什么时候写程序要注意这个问题?zero-sized array vs pointer
问一个简单问题为什么有点函数声明的参数类型但是没有变量名呢?
相关话题的讨论汇总
话题: bit话题: size话题: 64话题: windows话题: int
进入Programming版参与讨论
1 (共1页)
s*****w
发帖数: 1527
1
basically want to have a type like this,
for 32 bit windows, it's 32-bit int,
for 64-bit windows, it's 64-bit long long.
so i can use size_t for both user mode and kernel, for both 32-bit and 64-
bit windows ?
note unix is much better, int is portable.
n**f
发帖数: 121
2
Gut feeling is that size_t is at most as portable as int. If you have issues
porting int, size_t will probably fail.
Just curious why you are concerned with portability of size_t? 32 vs. 64 bit
should only matters if you are dealing with things like numerical
computation (and thus the numbers are so large).

【在 s*****w 的大作中提到】
: basically want to have a type like this,
: for 32 bit windows, it's 32-bit int,
: for 64-bit windows, it's 64-bit long long.
: so i can use size_t for both user mode and kernel, for both 32-bit and 64-
: bit windows ?
: note unix is much better, int is portable.

s*****w
发帖数: 1527
3
if you want to get the different for 2 pointers,
they are either 32-bit pointers or 64-bit, the result comes back as an int
or int64, that's why i was thinking about size_t

issues
bit

【在 n**f 的大作中提到】
: Gut feeling is that size_t is at most as portable as int. If you have issues
: porting int, size_t will probably fail.
: Just curious why you are concerned with portability of size_t? 32 vs. 64 bit
: should only matters if you are dealing with things like numerical
: computation (and thus the numbers are so large).

s*****w
发帖数: 1527
4
ok, in my 64-bit pc,
size_t = unsigned log long
in 32-bit, it's unsigned int which is int32

issues
bit

【在 n**f 的大作中提到】
: Gut feeling is that size_t is at most as portable as int. If you have issues
: porting int, size_t will probably fail.
: Just curious why you are concerned with portability of size_t? 32 vs. 64 bit
: should only matters if you are dealing with things like numerical
: computation (and thus the numbers are so large).

n**f
发帖数: 121
5
Are you trying to infer the distance between two array elements?

【在 s*****w 的大作中提到】
: if you want to get the different for 2 pointers,
: they are either 32-bit pointers or 64-bit, the result comes back as an int
: or int64, that's why i was thinking about size_t
:
: issues
: bit

s*****w
发帖数: 1527
6
a simpled version
pdest = _tcsstr(string, _T("pattern") ); // which is a strstr in ascii
result = pdest - string + 1;
printf ("pattern is found at position %d of the string");

【在 n**f 的大作中提到】
: Are you trying to infer the distance between two array elements?
n**f
发帖数: 121
7
My 2 cents is that: if an int fails in any edge case, a size_t will probably
fail too.
Also see the example in MSDN
http://msdn.microsoft.com/en-us/library/z9da80kz(v=vs.80).aspx
They use int.

【在 s*****w 的大作中提到】
: a simpled version
: pdest = _tcsstr(string, _T("pattern") ); // which is a strstr in ascii
: result = pdest - string + 1;
: printf ("pattern is found at position %d of the string");

t****t
发帖数: 6806
8
the type of the difference of two pointers is ptrdiff_t, not size_t. size_t
is unsigned, while ptrdiff_t is signed.

【在 s*****w 的大作中提到】
: if you want to get the different for 2 pointers,
: they are either 32-bit pointers or 64-bit, the result comes back as an int
: or int64, that's why i was thinking about size_t
:
: issues
: bit

1 (共1页)
进入Programming版参与讨论
相关主题
为什么有点函数声明的参数类型但是没有变量名呢?Java的POD比C++干净很多
指针的大小是 4 byte还是有赖于系统?请教一个C的问题
Why do I need to use "plain" pointer?什么时候写程序要注意这个问题?
一个简单的小问题问一个简单问题
pointer overflowQuestion about data member offset
C++ 菜鸟问一个关于template 的问题。C++中size_type怎么处理?
说起来上次谁推荐的memmove作面试题来着What is size_t mean in C?
C 中的typedef 一问狠偷懒狠偷懒的一个测试
相关话题的讨论汇总
话题: bit话题: size话题: 64话题: windows话题: int