limits.h问题 [英] limits.h question

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

问题描述

嘿,我正在学习限制标题,我不理解一个代码的b
snippit代码。如果我代码:


#include< limits.h>

#include< stdio.h>

int main ()

{

printf(最小签名长long:%lld \ n,LLONG_MIN);

返回0;

}

我得到输出:

最小签名长多头:0


为什么这样?我甚至检查了我的limits.h文件,在那里我看到:

#define LLONG_MIN 0x8000000000000000 / *最小签名__int64值* /


为什么赢了''打印限制?

解决方案

顺便说一句......这可能不是主题,但如果我在c ++中编写相同的东西

与cout<<它运作正常......很奇怪

Mark Bruno <亚************* @ yahoo.com>在消息中写道

新闻:3M ******************** @ comcast.com ...

嘿,我正在学习限制标题,我不明白一个代码的snippit。如果我编码:

#include< limits.h>
#include< stdio.h>
int main()
{
printf (最小签名长long:%lld \ n,LLONG_MIN);
返回0;
}
我得到输出:
最小签名长long:0

这是为什么?我甚至检查了我的limits.h文件,我看到了:
#define LLONG_MIN 0x8000000000000000 / *最小签名__int64值
* /
为什么不打印限制?



Mark Bruno写道:

嘿,我正在学习限制标题,我不知道理解一个代码的snippit。如果我编码:

#include< limits.h>
#include< stdio.h>
int main()
{
printf (最小签名长long:%lld \ n,LLONG_MIN);
返回0;
}
我得到输出:
最小签名长long:0

这是为什么?我甚至检查了我的limits.h文件,我看到了:
#define LLONG_MIN 0x8000000000000000 / *最小签名__int64值* /

为什么不打印限制?




您似乎正在使用< limits.h>不适合你的
编译器。确保你没有不匹配。为了比较,我得到了

我的实现:


#include< limits.h>

#include< stdio .h>

int main(无效)

{

printf(最小签名长多头:%lld \ n,LLONG_MIN );

printf(最小签名长:%ld \ n,LONG_MIN);

printf(最小签名int:%d \ n ,INT_MIN);

printf(最小签名短:%hd \ n,SHRT_MIN);

printf("最小签名字符:%d \ n",SCHAR_MIN);

printf(最大签名长long:%lld \ n,LLONG_MAX);

printf("最大无符号长long: %llu \ n",ULLONG_MAX);

printf(最大签名长:%ld \ n,LONG_MAX);

printf("最大的无符号) long:%lu \ n",ULONG_MAX);

printf(" Largest signed int:%d \ n",INT_MAX);

printf("最大的unsigned int:%u \ n&qu ot;,UINT_MAX);

printf(最大签名短:%hd \ n,SHRT_MAX);

printf("最大无符号短:%hu \ n",USHRT_MAX);

printf("最大签名字符:%d \ n",SCHAR_MAX);

printf("最大的unsigned char: %u \ n",UCHAR_MAX);

返回0;

}


最小签名长多头:-9223372036854775808

最小签名长:-2147483648

最小签名int:-2147483648

最小签名短:-32768

最小签名字符:-128

最大签名长多头:9223372036854775807

最大无签名长多头:18446744073709551615

最大签名长:2147483647

最大的无符号长:4294967295

最大签名int:2147483647

最大的unsigned int:4294967295

最大签名短:32767

最大的无符号短片:65535

最大签名字符:127

最大的未签名字符:255


-

Martin Ambuhl


我正在使用MS Visual C ++ 7.1(.net 2003),带有所有合适的标题。

任何有MSVC ++ 7.1的人都可以担保这个bug吗?

" Martin Ambuhl" <毫安***** @ earthlink.net>在消息中写道

news:xF ****************** @ newsread3.news.atl.earth link.net ...

Mark Bruno写道:

嘿,我正在学习限制标题,而且我不理解一个代码的snippit。如果我编码:

#include< limits.h>
#include< stdio.h>
int main()
{
printf (最小签名长long:%lld \ n,LLONG_MIN);
返回0;
}
我得到输出:
最小签名长long:0

这是为什么?我甚至检查了我的limits.h文件,我看到了:
#define LLONG_MIN 0x8000000000000000 / *最小签名__int64值
* /
为什么不打印限制?



您似乎正在使用< limits.h>不适合您的
编译器。确保你没有不匹配。为了比较,我得到了
我的实现:

#include< limits.h>
#include< stdio.h>
int main(void)
{
printf(最小签名长long:%lld \ n,LLONG_MIN);
printf(最小签名长:%ld \ n,LONG_MIN);
printf(Smallest signed int:%d \ n,INT_MIN);
printf(最小签名短:%hd \ n,SHRT_MIN);
printf( 最小签名字符:%d \ n,SCHAR_MIN);
printf(最大签名长long:%lld \ n,LLONG_MAX);
printf("最大unsigned long long:%llu \ n",ULLONG_MAX);
printf(最大签名长:%ld \ n,LONG_MAX);
printf("最大无符号长:%lu \ n,ULONG_MAX);
printf(Largest signed int:%d \ n,INT_MAX);
printf(Largest unsigned int:%u \ n,UINT_MAX);
printf(最大签名短:%hd \ n,SHRT_MAX);
printf(最大无符号短:%hu \ n,USHRT_MAX);
printf(最大签名char:%d \ n",SCHAR_MAX);
printf(最大的unsigned char:%u \ n,UCHAR_MAX);
返回0;
}

最小签名长多头:-9223372036854775808
最小签名长:-2147483648
最小签名int:-2147483648
最小签名短:-32768
最小签名字符: - 128
最大签名长多头:9223372036854775807
最大无符号长多头:18446744073709551615
最大签名长:2147483647
最大无符号长:4294967295
最大签名int:2147483647
最大的unsigned int:4294967295
最大的签名短:32767
最大的无符号短:65535
最大的签名字符:127
最大的无符号字符:255

-
Martin Ambuhl



Hey, I''m learning about the limits header, and I don''t understand one
snippit of code. If I code:

#include <limits.h>
#include <stdio.h>
int main()
{
printf("Smallest signed long long: %lld\n", LLONG_MIN);
return 0;
}
I get the output:
Smallest signed long long: 0

Why is this? I even check in my limits.h file, where I see:
#define LLONG_MIN 0x8000000000000000 /*minimum signed __int64 value */

Why won''t it print the limit?

解决方案

By the way...this might be off topic, but if i code the same thing in c++
with cout << it works ok...weird
"Mark Bruno" <ya*************@yahoo.com> wrote in message
news:3M********************@comcast.com...

Hey, I''m learning about the limits header, and I don''t understand one
snippit of code. If I code:

#include <limits.h>
#include <stdio.h>
int main()
{
printf("Smallest signed long long: %lld\n", LLONG_MIN);
return 0;
}
I get the output:
Smallest signed long long: 0

Why is this? I even check in my limits.h file, where I see:
#define LLONG_MIN 0x8000000000000000 /*minimum signed __int64 value */
Why won''t it print the limit?



Mark Bruno wrote:

Hey, I''m learning about the limits header, and I don''t understand one
snippit of code. If I code:

#include <limits.h>
#include <stdio.h>
int main()
{
printf("Smallest signed long long: %lld\n", LLONG_MIN);
return 0;
}
I get the output:
Smallest signed long long: 0

Why is this? I even check in my limits.h file, where I see:
#define LLONG_MIN 0x8000000000000000 /*minimum signed __int64 value */

Why won''t it print the limit?



It would seem that you are using a <limits.h> not appropriate for your
compiler. Make sure that you don''t have a mismatch. For comparison, I get
for my implementation:

#include <limits.h>
#include <stdio.h>
int main(void)
{
printf("Smallest signed long long: %lld\n", LLONG_MIN);
printf("Smallest signed long: %ld\n", LONG_MIN);
printf("Smallest signed int: %d\n", INT_MIN);
printf("Smallest signed short: %hd\n", SHRT_MIN);
printf("Smallest signed char: %d\n", SCHAR_MIN);
printf("Largest signed long long: %lld\n", LLONG_MAX);
printf("Largest unsigned long long: %llu\n", ULLONG_MAX);
printf("Largest signed long: %ld\n", LONG_MAX);
printf("Largest unsigned long: %lu\n", ULONG_MAX);
printf("Largest signed int: %d\n", INT_MAX);
printf("Largest unsigned int: %u\n", UINT_MAX);
printf("Largest signed short: %hd\n", SHRT_MAX);
printf("Largest unsigned short: %hu\n", USHRT_MAX);
printf("Largest signed char: %d\n", SCHAR_MAX);
printf("Largest unsigned char: %u\n", UCHAR_MAX);
return 0;
}

Smallest signed long long: -9223372036854775808
Smallest signed long: -2147483648
Smallest signed int: -2147483648
Smallest signed short: -32768
Smallest signed char: -128
Largest signed long long: 9223372036854775807
Largest unsigned long long: 18446744073709551615
Largest signed long: 2147483647
Largest unsigned long: 4294967295
Largest signed int: 2147483647
Largest unsigned int: 4294967295
Largest signed short: 32767
Largest unsigned short: 65535
Largest signed char: 127
Largest unsigned char: 255


--
Martin Ambuhl


I''m using MS Visual C++ 7.1 (.net 2003), with all the appropriate headers.
Anyone with MSVC++7.1 out there who can vouch for this bug?
"Martin Ambuhl" <ma*****@earthlink.net> wrote in message
news:xF******************@newsread3.news.atl.earth link.net...

Mark Bruno wrote:

Hey, I''m learning about the limits header, and I don''t understand one
snippit of code. If I code:

#include <limits.h>
#include <stdio.h>
int main()
{
printf("Smallest signed long long: %lld\n", LLONG_MIN);
return 0;
}
I get the output:
Smallest signed long long: 0

Why is this? I even check in my limits.h file, where I see:
#define LLONG_MIN 0x8000000000000000 /*minimum signed __int64 value */
Why won''t it print the limit?



It would seem that you are using a <limits.h> not appropriate for your
compiler. Make sure that you don''t have a mismatch. For comparison, I get
for my implementation:

#include <limits.h>
#include <stdio.h>
int main(void)
{
printf("Smallest signed long long: %lld\n", LLONG_MIN);
printf("Smallest signed long: %ld\n", LONG_MIN);
printf("Smallest signed int: %d\n", INT_MIN);
printf("Smallest signed short: %hd\n", SHRT_MIN);
printf("Smallest signed char: %d\n", SCHAR_MIN);
printf("Largest signed long long: %lld\n", LLONG_MAX);
printf("Largest unsigned long long: %llu\n", ULLONG_MAX);
printf("Largest signed long: %ld\n", LONG_MAX);
printf("Largest unsigned long: %lu\n", ULONG_MAX);
printf("Largest signed int: %d\n", INT_MAX);
printf("Largest unsigned int: %u\n", UINT_MAX);
printf("Largest signed short: %hd\n", SHRT_MAX);
printf("Largest unsigned short: %hu\n", USHRT_MAX);
printf("Largest signed char: %d\n", SCHAR_MAX);
printf("Largest unsigned char: %u\n", UCHAR_MAX);
return 0;
}

Smallest signed long long: -9223372036854775808
Smallest signed long: -2147483648
Smallest signed int: -2147483648
Smallest signed short: -32768
Smallest signed char: -128
Largest signed long long: 9223372036854775807
Largest unsigned long long: 18446744073709551615
Largest signed long: 2147483647
Largest unsigned long: 4294967295
Largest signed int: 2147483647
Largest unsigned int: 4294967295
Largest signed short: 32767
Largest unsigned short: 65535
Largest signed char: 127
Largest unsigned char: 255


--
Martin Ambuhl



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

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