Thread: long int type

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    11

    long int type

    Hi every body!

    I hope you guys are having a good day.

    I was reading about long int type in c++. Here is what i find:


    A signed long can hold all the values between LONG_MIN and LONG_MAX inclusive. LONG_MIN is required to be -2147483647 or less,A signed long can hold all the values between LONG_MIN and LONG_MAX inclusive. LONG_MIN is required to be -2147483647 or less, LONG_MAX must be at least 2147483647. Again, many 2's complement implementations will define LONG_MIN to be -2147483648 but this is not required.

    An unsigned long can hold all the values between 0 and ULONG_MAX inclusive. ULONG_MAX must be at least 4294967295. The long types must contain at least 32 bits to hold the required range of values. LONG_MIN to be -2147483648 but this is not required.

    An unsigned long can hold all the values between 0 and ULONG_MAX inclusive. ULONG_MAX must be at least 4294967295. The long types must contain at least 32 bits to hold the required range of values.
    ================================================== ===


    "long - min is required to be -21478364 or less",
    my question is how much less? why long_min is required to be -214783647?

    "A LONG_MAX must be at least 2147483647." why long-max must be atleast 2147483647?



    Thanks a lot and have a nice day!
    Last edited by sarahr202; 05-20-2009 at 09:41 AM. Reason: correction

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    The point of the standard is to guarantee something. You know, no matter where you go (assuming a standard-compliant implementation) that a long int can handle that range. Some machines may give you a larger range, and a larger range would require a smaller number than -2147483648. The numbers were chosen as the range from LONG_MIN to LONG_MAX is a power of 2, specifically 2^32.

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    -2147483647 or less, not -214748364.

    How much less? How about 9223372034707292161 less? That's a real result, taken from GCC running on a 64-bit Linux. There's no limit, really.

    Why -2147483647? Because that's -(2^31 - 1), which is the smallest value a signed 32-bit value can take in a one's complement or sign/magnitude negative representation. The standard thus enforces this:
    1) long (which is a synonym for long int) must be at least 32 bits wide (but may be wider).
    2) One's complement and sign/magnitude are valid negative representations. So is two's complement, the most common representation these days.

    And that large value I wrote above? That's the difference between -(2^63) (the lowest value a two's complement 64-bit integer can take) and -(2^31-1).
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Those values imply that you are dealing with a number that is AT LEAST 32 bits. If we have a 36-bit processor, we can make long a 36-bit number. On a 64-bit machine that also supports 32-bit numbers, it can use EITHER 32 or 64-bit numbers - the spec allows the choice to be made by the implementation. In fact, in x86-64 for Linux, a long is 64-bit, and in x86-64 running Windows, long is 32-bit.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    11
    Thanks a lot guys for awesome responses!

    have a nice day!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to combine these working parts??
    By transgalactic2 in forum C Programming
    Replies: 0
    Last Post: 02-01-2009, 08:19 AM
  2. Drawing Program
    By Max_Payne in forum C++ Programming
    Replies: 21
    Last Post: 12-21-2007, 05:34 PM
  3. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 03:49 PM
  4. Game Won't Compile
    By jothesmo in forum C++ Programming
    Replies: 2
    Last Post: 04-01-2006, 04:24 PM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM