data type ranges, what is the largest?

This is a discussion on data type ranges, what is the largest? within the C++ Programming forums, part of the General Programming Boards category; I was wondering what is the largest range any data type can hold and still be portable to another OS? ...

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    12

    data type ranges, what is the largest?

    I was wondering what is the largest range any data type can hold and still be portable to another OS? I noticed MSVC++ compiler can compile __int64, which is the numbered range I need for this program I am working on. But it gives me this error:
    Code:
    __int64 count;
    .
    .
    cout << "\n		Moves: \t\t\t\t" << count;
    .
    .
    Compiler Error:
    Code:
    error C2593: 'operator <<' is ambiguous
    when I try to output it to cout. Here's what MSDN says about this:
    "The types __int8, __int16, and __int32 are synonyms for the ANSI types that have the same size, and are useful for writing portable code that behaves identically across multiple platforms. Note that the __int8 data type is synonymous with type char, __int16 is synonymous with type short, and __int32 is synonymous with type int. The __int64 type has no ANSI equivalent."

    How can I display a counter big enough to hold at least 18 digits without making my own class or struct?

  2. #2
    twm
    twm is offline
    root
    Join Date
    Sep 2003
    Posts
    232
    I don't think cout recognizes __int64. Check MSDN to see if there's a fix for that, I think I read something about it a while back.
    The information given in this message is known to work on FreeBSD 4.8 STABLE.
    *The above statement is false if I was too lazy to test it.*
    Please take note that I am not a technical writer, nor do I care to become one.
    If someone finds a mistake, gleaming error or typo, do me a favor...bite me.
    Don't assume that I'm ever entirely serious or entirely joking.

  3. #3
    Registered User
    Join Date
    Oct 2003
    Posts
    12
    I know it doesn't, and I have a bad feeling keeping my program portable from windows to linux to whatever, I am going to have to make my own class or function or something that is at least 18 digits long, but that seems like an awful lot of overhead just for a counter to add 1 digit each time a function gets called. seems like to many if statements......

  4. #4
    Master of the Universe! velius's Avatar
    Join Date
    Sep 2003
    Posts
    219
    I assume that about 4.9 billion from an unsigned int is not long enough? You could convert your __int64 to a string first with char *_i64toa( __int64 value, char *string, int radix ) which is microsoft specific. I do believe that GNU uses intint to declare a 64 bit int. I don't know if that function even comes close for them.
    While you're breakin' down my back n'
    I been rackin' out my brain
    It don't matter how we make it
    'Cause it always ends the same
    You can push it for more mileage
    But your flaps r' wearin' thin
    And I could sleep on it 'til mornin'
    But this nightmare never ends
    Don't forget to call my lawyers
    With ridiculous demands
    An you can take the pity so far
    But it's more than I can stand
    'Cause this couchtrip's gettin' older
    Tell me how long has it been
    'Cause 5 years is forever
    An you haven't grown up yet
    -- You Could Be Mine - Guns N' Roses

  5. #5
    Registered User
    Join Date
    Oct 2003
    Posts
    12
    Thanks, I think I will try that first, before figuring out a class or struct or something.

  6. #6
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    Wait, cout recognizes __int64 just fine.
    Code:
    #include <iostream>
    int main()
    {
        __int64 myInt = 9223372036854775807;
        std::cout << "Big number: " << myInt << std::endl;
    }
    compiles and runs on my VC++ 6.0.

    I get that error if I use the old <iostream.h> header. Switch to the correct header and it will work.

  7. #7
    Registered User
    Join Date
    Oct 2003
    Posts
    12
    Umm, how does it work on your system and not mine?
    Code:
    #include <iostream>
    int main()
    {
        __int64 myInt = 9223372036854775807;
        std::cout << "Big number: " << myInt << std::endl;
    	return 0;
    }
    Code:
    Compiling...
    test.cpp
    C:\Documents and Settings\Administrator\Desktop\test\test.cpp(5) : error C2593: 'operator <<' is ambiguous
    Error executing cl.exe.
    
    test.obj - 1 error(s), 0 warning(s)
    This was the error from your code, I tried mine first but it gave me 32 errors because cout was not recognized nor was "<<", then I tried your code, and the above error is what I got. I have Microsoft Visual Studio 6 with SP1 installed, Windows XP Proffessional. No .net to be found on my system.
    Last edited by timberwolf5480; 10-16-2003 at 12:49 PM.

  8. #8
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    Notice the difference between <iostream> and <iostream.h>

    The one without the '.h' is the newer standard header, the one with the '.h' is old.

    If you use the new one, cout, endl, etc. are in the namespace std. If you don't know namespaces, don't worry, just do one of the following:

    1. Put using namespace std; under the includes. This is the easiest to do an works fine for small projects.
    Code:
    #include <iostream>
    using namespace std;
    int main()
    {
        __int64 myInt = 9223372036854775807;
        cout << "Big number: " << myInt << endl;
        return 0;
    }
    2. Put using namespace std::XXXX; under the includes for each thing you use from the header. Some people prefer this over the first one.
    Code:
    #include <iostream>
    using namespace std::cout;
    using namespace std::endl;
    int main()
    {
        __int64 myInt = 9223372036854775807;
        cout << "Big number: " << myInt << endl;
        return 0;
    }
    3. Put std:: in front of each thing you use from the header every time you use it in the code. This is what I did in my sample and is my preferred way of writing it. It tends to look cluttered, but you should get used to it.
    Code:
    #include <iostream>
    int main()
    {
        __int64 myInt = 9223372036854775807;
        std::cout << "Big number: " << myInt << std::endl;
        return 0;
    }
    All three of those should work. If you did copy it exactly and it still doesn't work, then I'm not sure what the problem is. I use Visual C++ 6.0 with a different STL implementation from Dinkumware. It is possible that they fixed a problem with this in that implementation but not in the one that ships with VC++.

  9. #9
    Registered User
    Join Date
    Oct 2003
    Posts
    12
    Nope, tried all three examples and it still doesn't work, I think it may have something to do with how our compilers are set up somehow, I tried all three on my Windows XP machine, and then on my Windows 98 pre-SP1 for VC++6 laptop, all 6 attempts failed. The program I am working on is a Hanoi Towers recursive function program. I am doing this project to "get back into the game" so to speak. I would like to see how long it takes to run all 64 discs on various hardware around the neighborhood including all my computers. I need a data type to hold the count of this counter, it counts the moves it makes. It is my goal to either see all 64 discs get completed, or my favorite, the machine crash and burn because recursion filled it's memory, it happened once on an old Pentium 100 overclocked to 120, 3 days after running, it died hehe.

  10. #10
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    There is a way to represent a 64-bit integer using 2 32-bit registers or 2 32 bit values - check on www.google.com for more info concerning this topic. Also you can use the double data type which is 64-bits since the native data type of the FPU is 64-bits.

    Using double as a data type is not slower than using single or using integer. In fact when you specify double, the compiler should automatically stick your values into FPU registers. Floating point operations on new CPUs are as fast as or faster than integer operations. And if you are not going to actually use anything beyond the decimal point, you still get the precision and speed that comes with using the FPU.

    As well you can use the MMX packed data types to represent large numbers and do computations on them. Check out the MMX manual or go to www.intel.com and download it from their website. Their are several opcodes that are well suited for this task.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 09:18 PM
  2. Replies: 0
    Last Post: 03-20-2008, 08:59 AM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-30-2005, 12:21 AM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 11:03 AM
  5. All u wanted to know about data types&more
    By SAMSAM in forum Windows Programming
    Replies: 6
    Last Post: 03-11-2003, 03:22 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21