找到size_t的最大值 [英] finding max value of size_t
问题描述
考虑以下计划
#include< limits.h>
#include< stddef.h>
>
int main(无效)
{
size_t size;
size_t bytes = sizeof(size_t);
if(bytes == sizeof(unsigned int))
size = UINT_MAX;
else if(bytes == sizeof(unsigned long) )
size = ULONG_MAX;
else if(bytes == sizeof(unsigned long long))
size = ULLONG_MAX;
返回0;
}
此代码可以在所有标准C中给出size_t的最大值
$符合b $ b标准的编译器。
su ************** @ yahoo.com ,印度说:
考虑以下计划
#include< limits.h>
#include< stddef.h>
int main(无效)
{
size_t size;
size_t bytes = sizeof(size_t);
if(bytes == sizeof(unsigned int))
size = UINT_MAX;
else if(bytes == sizeof(unsigned long))
size = ULONG_MAX;
else if(bytes == sizeof(unsigned long long))
size = ULLONG_MAX;
返回0;
}
>
此代码可以在所有标准C
兼容编译器中提供size_t的最大值。
否,因为无法保证size_t的大小与任何其他整数类型相同。但你可以这样做:
#include< stddef.h>
int main(无效)
{
size_t size =(size_t)-1;
返回0;
}
-
Richard Heathfield
Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk
电子邮件:rjh在上述域名中, - www。
(size_t) - 1
>
请告诉我这是否会给出size_t的最大价值
blockquote>
su ************** @ yahoo.com ,印度说:
(size_t) - 1
请告知我这是否会给出size_t
的最大价值
难道我不是那样做的吗?是的,它会的。
-
Richard Heathfield
Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk
电子邮件:rjh在上述域名中, - www。
Consider the following program
#include <limits.h>
#include <stddef.h>
int main(void)
{
size_t size;
size_t bytes = sizeof(size_t);
if (bytes == sizeof(unsigned int))
size = UINT_MAX;
else if (bytes == sizeof(unsigned long))
size = ULONG_MAX;
else if (bytes == sizeof(unsigned long long))
size = ULLONG_MAX;
return 0;
}
Can this code give the maximum value of size_t in all standard C
compliant compilers.
解决方案su**************@yahoo.com, India said:
Consider the following program
#include <limits.h>
#include <stddef.h>
int main(void)
{
size_t size;
size_t bytes = sizeof(size_t);
if (bytes == sizeof(unsigned int))
size = UINT_MAX;
else if (bytes == sizeof(unsigned long))
size = ULONG_MAX;
else if (bytes == sizeof(unsigned long long))
size = ULLONG_MAX;
return 0;
}
Can this code give the maximum value of size_t in all standard C
compliant compilers.No, because there is no guarantee that size_t has the same size as any
other integer type. But you can do this:
#include <stddef.h>
int main(void)
{
size_t size = (size_t)-1;
return 0;
}
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
(size_t) - 1
Please let me know whether this will give the maximum value of size_t
su**************@yahoo.com, India said:
(size_t) - 1
Please let me know whether this will give the maximum value of size_tDidn''t I just do that? Yes, it will.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
这篇关于找到size_t的最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!