Thread: Best way to ensure variable lengths stay the same across i386/x86_64?

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    101

    Best way to ensure variable lengths stay the same across i386/x86_64?

    I am trying to write code portable across 32 bit and 64 bit systems, and want to know the best, most portable way to ensure the variables stay the right length. For example, "int" is 4 bytes in 32 bit, but 8 in 64 bit. Should I declare as "long int" for 4 bytes and "long long int" for 8 bytes instead? I am not sure what the best practice is moving forward.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    If you want 4 bytes use "int32_t" and if you want 8 bytes "int64_t". (MS has their own nonstandard names for these, but its similar.)

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Use arrays of characters and do all of your calculations manually.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Use of variable
    By alice in forum C Programming
    Replies: 8
    Last Post: 06-05-2004, 07:32 AM
  2. float/double variable storage and precision
    By cjschw in forum C++ Programming
    Replies: 4
    Last Post: 07-28-2003, 06:23 PM
  3. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 02:45 PM
  4. Need help
    By awkeller in forum C Programming
    Replies: 2
    Last Post: 12-09-2001, 03:02 PM
  5. Variable Allocation in a simple operating system
    By awkeller in forum C Programming
    Replies: 1
    Last Post: 12-08-2001, 02:26 PM