CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 19

Thread: Integer Range

  1. #1
    Join Date
    Jul 2006
    Posts
    141

    Integer Range

    Hello

    Declaring an __int64 or long long in VS2010 has the same range as an int while double works fine.

    Checked MSDN over and over and can see no reason why this data range should not be 64 bit.

    Any help is much appreciated.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Integer Range

    What is your system?
    What did you expect?
    What did you get instead?
    Some code snippet would also help
    Victor Nijegorodov

  3. #3
    Join Date
    Jul 2006
    Posts
    141

    Re: Integer Range

    System: 32 bit windows 7 Visual Studio 2010
    Expected 64 bit range (as double works fine)
    got 32 bit range

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: Integer Range

    What does sizeof(__int64) give?

    With my VS2010 this program
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
    	cout << sizeof(long long) << endl;
    }
    produces 8 (ie 64 bit) for both 32 and 64 bit builds
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  5. #5
    Join Date
    Jul 2006
    Posts
    141

    Re: Integer Range

    Same here, sizeof(long long)==8

    But when I assign 5000000000 to the variable I get 705032704.

  6. #6
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Integer Range

    Quote Originally Posted by quorsum View Post
    But when I assign 5000000000 to the variable I get 705032704.
    As Victor noted, "Some code snippet would also help"
    HOW do you assign that value to that variable?

    P.S. Here is a short demo - can you see the difference?
    Code:
    long long ll_1 = 5000000000;
    long long ll_2 = 50000*100000;
    Last edited by VladimirF; May 13th, 2015 at 04:50 PM.
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  7. #7
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: Integer Range

    Well on my VS2010 this
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
    	cout << sizeof(long long) << endl;
    
    	long long ll =  5000000000;
    
    	cout << ll << endl;
    }
    produces
    Code:
    8
    5000000000
    ??
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  8. #8
    Join Date
    Jul 2006
    Posts
    141

    Re: Integer Range

    Thanks 2kaud

    I always suspected something fishy with my system. But what is the explanation I wonder.

  9. #9
    Join Date
    Jul 2006
    Posts
    141

    Re: Integer Range

    VladimirF

    long long test=5000000000;

  10. #10
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Integer Range

    Code:
    #include <windows.h>
    #include <stdio.h>
    
    int main()
    {
        __int64  i64 = 5000000000;
        long long ll = 6000000000;
    
        printf("i64 (%li) = %I64i\n", sizeof(i64), i64);
        printf(" ll (%li) = %lli\n",  sizeof(ll),   ll);
    
        return 0;
    }
    Code:
    J:\Temp\76>cl 76.cpp
    Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    76.cpp
    Microsoft (R) Incremental Linker Version 10.00.40219.01
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    /out:76.exe
    76.obj
    
    J:\Temp\76>76.exe
    i64 (8) = 5000000000
     ll (8) = 6000000000
    Best regards,
    Igor

  11. #11
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Integer Range

    The next question is: how do you check the value after that assignment?
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  12. #12
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Integer Range

    Quote Originally Posted by quorsum View Post
    Thanks 2kaud

    I always suspected something fishy with my system. But what is the explanation I wonder.
    YOU are doing something wrong, or YOU are interpreting results the wrong way.
    if your system really was that fishy, it wouldn't even be able to boot into windows.

    So as has been asked several times.
    Produce actual code that either SHOWS the error, or screenshot of how you think you get that wrong answer

  13. #13
    Join Date
    Jul 2013
    Posts
    576

    Re: Integer Range

    Quote Originally Posted by quorsum View Post
    long long test=5000000000;
    To denote a long long literal you need to add one of the suffixes l or L like

    long long test = 5000000000L;
    Last edited by razzle; May 15th, 2015 at 10:29 AM.

  14. #14
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Integer Range

    Quote Originally Posted by razzle View Post
    To denote a long long literal you need to add one of the suffixes l or L...
    As I understand it, you only need to use these suffixes if the value may get misinterpreted.
    Here, the long long value is assigned to long long variable; works for me without the suffix.
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  15. #15
    Join Date
    Jul 2013
    Posts
    576

    Re: Integer Range

    Quote Originally Posted by VladimirF View Post
    As I understand it, you only need to use these suffixes if the value may get misinterpreted.
    Here, the long long value is assigned to long long variable; works for me without the suffix.
    That works for me too.

    But there's a certain amount of implementation dependency at play here and it's never wrong to be explicit about the literal type.

    Also it seems in C++ 11 it's preferred to let the variable type be deducted from the literal type rather than the other way around like,

    auto test = 5000000000L;

    or

    auto test = static_cast<long long>(5000000000);
    Last edited by razzle; May 15th, 2015 at 03:55 PM.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured