Thread: Cross Platform Compatible 64Bit And 8Bit Integer

  1. #1
    Registered User
    Join Date
    Feb 2003

    Cross Platform Compatible 64Bit And 8Bit Integer

    Im looking for cross-platform compatible 64bit And 8Bit integer datatypes to use. It is my understanding the 64bit ones are somewhat compiler specific, but i can hope cant i? Im using Visual C++ 6 on the dark side, and on the light im running G++ 3.4. The 8bit one is probablly what drew you to auctually click on this thread, and yes im aware that technicly unsigned characters could do the job, but im looking for a true one like __int8. Also i understand that if i wanted to store 8 bytes, i could use a double, however thats not interpited as an integer, and my needs are more complex than simply storing a binary value. Attempting to use substitutes for either of the 8 or 64bit integers always makes one compiler or the other extremely unhappy. Any help would be greatly appreciated.

    Thanks for your time.

  2. #2
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Couple things pop into mind:
    a. Use/make an arbitrarily sized integer class. This solution is going to be slower, and will rely on solution (b) anyway.
    b. typedef these types to a specific name using a long and nasty series of preprocessor commands (#if, etc). This will of course require digging through the documentation for the specific target platforms/compilers, and may not always be available.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  3. #3
    Registered User Kybo_Ren's Avatar
    Join Date
    Sep 2004
    I'd simply #define macros, "ALWAYS8BITS" and "ALWAYS64BITS" to __int8 and __int64 on VC++ 6, then change them for G++.

    Typedef'ing works, too. Matter of preference.
    Last edited by Kybo_Ren; 01-13-2005 at 10:51 PM.

  4. #4
    Registered User
    Join Date
    Feb 2003
    Well the second one, item B i already considered but found different versions of the same compilers too picky to make it an acceptable solution. People flat out complained when it would work on version 3.4 but not 2.95 or 4.x etc.

    Solution A sounds like its probablly the most promising solution, however i have never auctually writen an "integer object" before, so im open to suggestions as how to accomplish this. Should i store low to high, byte by byte, or should i store it in 4 byte unsigned integer chunks? Im assuming it will just be alot of operator overloading, and shifting numbers around. I really appreciate the help.

    Thanks for your time, and speedy reply.

  5. #5
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    #if defined(HAVE_STDINT_H)
    #include <stdint.h>
     typedef unsigned char   uint8_t;
     typedef unsigned short  uint16_t;
     typedef unsigned long   uint32_t;
     typedef signed   char   int8_t;
     typedef signed   short  int16_t;
     typedef signed   long   int32_t;
    #if defined(_MSC_VER) && (_MSC_VER <= 1200)
     /* MSVC 6 or earlier */
     typedef signed   __int64  int64_t
     typedef unsigned __int64  uint64_t
     typedef signed   long long int64_t
     typedef unsigned long long uint64_t
    Last edited by anonytmouse; 01-13-2005 at 10:59 PM.

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    As anonytmouse shows, some modern compilers have the stdint.h header required by C99.

    The Boost libraries contain the cstdint.hpp header, which emulates stdint.h for compilers that don't have it. That's what I always use.
    All the buzzt!

    "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

Popular pages Recent additions subscribe to a feed