例2.1,K&安培; R:为LONG_MIN和LONG_MAX错误符号常量的值? [英] Example 2.1, K&R: Wrong symbolic constants value for LONG_MIN and LONG_MAX?

查看:245
本文介绍了例2.1,K&安培; R:为LONG_MIN和LONG_MAX错误符号常量的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是code,我用它来寻找LONG符号常量的值

This is the code which I use to find the symbolic constant values for LONG

   #include <limits.h>     //These header files contains the symbolic constants
   #include <float.h>      //for different datatypes

   #include <stdio.h>

    int main(void){

            printf("\tMininum numeric value for long type: %ld\n", LONG_MIN);
            printf("\tMaximum numeric value for long type: %ld\n", LONG_MAX);

            printf("\tMaximum numeric value for unsigned long type: %lu\n", (unsigned)ULONG_MAX);
    return 0;
   }  

输出,我得到的是:

Output which I get is:

  Mininum numeric value for long type: -9223372036854775808
  Maximum numeric value for long type: 9223372036854775807
  Maximum numeric value for unsigned long type: 4294967295

但如果看到该名男子页的limits.h中。这些是 LONG_MIN LONG_MAX LLONG_MIN 符号常量和 LLONG_MAX 在我的系统 limits.h中文件。

But if see the limits.h from the man page. These are the symbolic constants for LONG_MIN, LONG_MAX, LLONG_MIN and LLONG_MAX from the limits.h file in my system.

  {LONG_MIN}
          Minimum value of type long.
          Maximum Acceptable Value: -2 147 483 647

  {LONG_MAX}
          Maximum value of a long.
          Minimum Acceptable Value: +2 147 483 647

  {LLONG_MIN}
          Minimum value of type long long.
          Maximum Acceptable Value: -9223372036854775807

  {LLONG_MAX}
          Maximum value of type long long.
          Minimum Acceptable Value: +9223372036854775807

仿佛,该方案是给我的价值观,从很久很久符号常量。

As if, the program is giving me the values from Long long symbolic constants.

为什么会出现这种情况?

Why is this happening?

推荐答案

显然您的系统上的64位。

Obviously long is 64 bits on your system.

C标准规定的下限的整数类型。也就是说,例如LONG_MAX必须的至少 2 147 483 647 ,但它可能是较大的。

The C standard specifies minimum limits for integer types. Meaning that for example LONG_MAX has to be at least 2 147 483 647, but it could be larger.

作为一个方面说明,这是一个错误:(无符号)ULONG_MAX 。应unsigned long类型。

As a side note, this is a bug: (unsigned)ULONG_MAX. Should be unsigned long.

一个有趣的好奇:注:例如该LONG_MIN有至少 -2 147 483 647 。但是,即使在常规32位二进制补体系统,它永远不会有一个价值!结果
它具有价值 -2 147 483 648 。这是有意这样做的让一个人的补充和签署&安培;震级系统。

One interesting curiousity: note for example that LONG_MIN has to be at least -2 147 483 647. But even on a regular 32 bit two complement system, it never has that value!
It has the value -2 147 483 648. This is done intentionally to allow one's complement and sign & magnitude systems.

这篇关于例2.1,K&安培; R:为LONG_MIN和LONG_MAX错误符号常量的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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