size_t文字? [英] size_t literals?

查看:73
本文介绍了size_t文字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



嗨!


在size_t为64位的机器上,unsigned long为32位,

是否构造了一个size_t文字,表示2 ^ 32?打字


size_t x = 4294967296UL;


抱怨价值对于未签名的长期来说太大了

(显然,一个人太大了。


非标准足够的UI64

编译器也不承认。


我应该构造值为4294967295UL然后增加

size_t变量?


TIA,

- J.


Hi!

On a machine where size_t is 64-bit, unsigned long is 32-bit, how
does one construct a size_t literal that says 2^32? Typing in

size_t x = 4294967296UL;

complains about the value being too large for unsigned long
(obviously, it''s too large by one).

The nonstandard suffices "UI64" are also not recognized by the
compiler.

Should I construct with a value of 4294967295UL and then increment
the size_t variable?

TIA,
- J.

推荐答案

ja ************ @ gmail.com 写道:

在size_t为64位的机器上,无符号长整数是32位,如何构造一个size_t字面值为2 ^ 32的

?打字


size_t x = 4294967296UL;


抱怨价值对于未签名的长期来说太大了

(显然,一个人太大了。


非标准足够的UI64

编译器也不承认。


我应该构造值为4294967295UL然后增加

size_t变量?
On a machine where size_t is 64-bit, unsigned long is 32-bit, how
does one construct a size_t literal that says 2^32? Typing in

size_t x = 4294967296UL;

complains about the value being too large for unsigned long
(obviously, it''s too large by one).

The nonstandard suffices "UI64" are also not recognized by the
compiler.

Should I construct with a value of 4294967295UL and then increment
the size_t variable?



由于''size_t''的表示不是由语言决定的,

你做的实现允许。如果''size_t''是64位,

那么你需要找到能满足你需要的类型。也许

一双。也许是一个未签名的长多?


size_t x = 4294967296ULL;


另一种可能性是得到2 ^ 16的值并将其平方:


size_t x =(size_t)(1 << 16)*(size_t)(1 << 16);


和希望编译器能够简化它并使其成为
a值而不是运行时表达式。


V

-

请在通过电子邮件回复时删除资金''A'

我没有回复最热门的回复,请不要问

Since the representation of ''size_t'' is not dictated by the language,
you do what your implementation allows. If your ''size_t'' is 64 bits,
then you need to find the type that would do what you need. Perhaps
a double. Maybe an unsigned long long?

size_t x = 4294967296ULL;

Another possibility is to get 2^16 value and square it:

size_t x = (size_t)(1 << 16) * (size_t)(1 << 16);

and hope that the compiler will be able to simplify it and make it
a value instead of a run-time expression.

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


2008-02-28 09:32:01 -0800, ja ************ @ gmail.com 说:
On 2008-02-28 09:32:01 -0800, ja************@gmail.com said:

>

嗨!


在size_t为64位的机器上,无符号长整数为32位,

如何构造size_t文字那说2 ^ 32?打字


size_t x = 4294967296UL;


抱怨价值对于未签名的长期来说太大了

(显然,一个人太大了。
>
Hi!

On a machine where size_t is 64-bit, unsigned long is 32-bit, how
does one construct a size_t literal that says 2^32? Typing in

size_t x = 4294967296UL;

complains about the value being too large for unsigned long
(obviously, it''s too large by one).



大概这是一个警告。编译器有义务将

值转换为合适的类型,尽管有后缀,并且您的代码应该按照您的预期工作。

Presumably this was a warning. The compiler is obliged to convert the
value to a suitable type, despite the suffix, and your code should
work as you expect it to.


>

非标准足以满足UI64的要求。

编译器也无法识别。
>
The nonstandard suffices "UI64" are also not recognized by the
compiler.



未来的标准将使用ULL或任何其他组合的案件用于那些

三个字母。

The future standard will use ULL, or any other mix of cases for those
three letters.


>

我应该构造值为4294967295UL然后增加

size_t变量吗?
>
Should I construct with a value of 4294967295UL and then increment
the size_t variable?



No.


-

Pete

Roundhouse咨询有限公司( www.versatilecoding.com
的作者
标准C ++库扩展:教程和参考

www.petebecker.com/tr1book

No.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)


ja ************ @ gmail.com 在新闻中写道:e6da1a2b-2561-4623-89a7-8303394cb7f9

@ k2g2000hse.googlegroups.com:
ja************@gmail.com wrote in news:e6da1a2b-2561-4623-89a7-8303394cb7f9
@k2g2000hse.googlegroups.com:

>

嗨!


在机器上size_t是64位,unsigned long是32位,怎么用
构造一个size_t文字,说2 ^ 32?打字


size_t x = 4294967296UL;


抱怨价值对于未签名的长期来说太大了

(显然,一个人太大了。


非标准足够的UI64

编译器也不承认。


我应该构造值为4294967295UL然后增加

size_t变量?


TIA,

- J.
>
Hi!

On a machine where size_t is 64-bit, unsigned long is 32-bit, how
does one construct a size_t literal that says 2^32? Typing in

size_t x = 4294967296UL;

complains about the value being too large for unsigned long
(obviously, it''s too large by one).

The nonstandard suffices "UI64" are also not recognized by the
compiler.

Should I construct with a value of 4294967295UL and then increment
the size_t variable?

TIA,
- J.



即将成为标准说明符怎么样? ULL?否则,数学

方法应该有效。


joe

What about the soon to be standard specifier of ULL? Otherwise, the math
method should work.

joe


这篇关于size_t文字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆