从size_t转换为unsigned int [英] convert from size_t to unsigned int
问题描述
大家好,
从size_t转换为unsigned int时,会出现一条警告消息,
警告C4267:''='':从''size_t''转换为''int'',可能会丢失数据
我不知道为什么,因为在crtdbg.h中,size_t被定义为int,对吗?
提前感谢,
George
Hello everyone,
When converting from size_t to unsigned int, there will be a warning message,
warning C4267: ''='' : conversion from ''size_t'' to ''int'', possible loss of data
I do not know why, since in crtdbg.h, size_t is defined to int, right?
thanks in advance,
George
推荐答案
" George"写道:
"George" wrote:
从size_t转换为unsigned int时,会出现一条警告信息,
警告C4267:'' ='':从''size_t''转换为''int'',可能会丢失数据
我不知道为什么,因为在crtdbg.h中,size_t被定义为int,对吗?
When converting from size_t to unsigned int, there will be a warning message,
warning C4267: ''='' : conversion from ''size_t'' to ''int'', possible loss of data
I do not know why, since in crtdbg.h, size_t is defined to int, right?
不,它被定义为unsigned int。并且你没有从size_t转换为
unsigned int,否则警告信息就不会出现。
best
doc
No, it is defined to unsigned int. And you are not converting from size_t to
unsigned int, otherwise the warning message wouldn''t come up.
best
doc
嗨doc,
我正在使用VS 2003.我发现即使我转换为unsigned int,错误
消息是一样的。
你知道原因吗?
问候,
乔治
" docschnipp"写道:
Hi doc,
I am using VS 2003. I find that even if I convert to unsigned int, the error
message is the same.
Do you know the reason?
regards,
George
"docschnipp" wrote:
" George"写道:
"George" wrote:
从size_t转换为unsigned int时,会出现一条警告信息,
警告C4267:'' ='':从''size_t''转换为''int'',可能会丢失数据
我不知道为什么,因为在crtdbg.h中,size_t被定义为int,对吗?
When converting from size_t to unsigned int, there will be a warning message,
warning C4267: ''='' : conversion from ''size_t'' to ''int'', possible loss of data
I do not know why, since in crtdbg.h, size_t is defined to int, right?
不,它被定义为unsigned int。并且你没有从size_t转换为
unsigned int,否则警告信息就不会出现。
best
doc
No, it is defined to unsigned int. And you are not converting from size_t to
unsigned int, otherwise the warning message wouldn''t come up.
best
doc
George写道:
::嗨doc,
::
::
::我正在使用VS 2003.我发现即使我转换为unsigned int,
::错误信息也是一样的。
::
::你知道原因吗?
1)这是兼容性警告,因为size_t没有在所有系统上都必须具有相同大小的
。特别是,对于64位编译,它与32位编译不同。
http://msdn2.microsoft.com/en-us/lib...93(VS.80).aspx
2)你为什么要首先这样做?为什么不使用size_t
变量?
Bo Persson
::
::
::问候,
:: George
::
::" docschnipp"写道:
::
:::" George"写道:
:::
::::当从size_t转换为unsigned int时,会有一个
::::警告消息,
::::
::::警告C4267:''='':从''size_t''转换为''int'',可能
::::数据丢失
::::
::::我不知道为什么,因为在crtdbg.h中,size_t定义为int,
::::对吗?
:::
:::不,它被定义为无符号INT。并且你没有将
:::从size_t转换为unsigned int,否则警告消息
:::不会出现。
:::
:::最好
::: doc
George wrote:
:: Hi doc,
::
::
:: I am using VS 2003. I find that even if I convert to unsigned int,
:: the error message is the same.
::
:: Do you know the reason?
1) It is a compatibility warning, because size_t doesn''t have to be
the same size on all systems. Particularly, for 64 bit compiles it is
different from a 32 bit compile.
http://msdn2.microsoft.com/en-us/lib...93(VS.80).aspx
2) Why do you want to do this in the first place? Why not use a size_t
variable?
Bo Persson
::
::
:: regards,
:: George
::
:: "docschnipp" wrote:
::
::: "George" wrote:
:::
:::: When converting from size_t to unsigned int, there will be a
:::: warning message,
::::
:::: warning C4267: ''='' : conversion from ''size_t'' to ''int'', possible
:::: loss of data
::::
:::: I do not know why, since in crtdbg.h, size_t is defined to int,
:::: right?
:::
::: No, it is defined to unsigned int. And you are not converting
::: from size_t to unsigned int, otherwise the warning message
::: wouldn''t come up.
:::
::: best
::: doc
这篇关于从size_t转换为unsigned int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!