long long array problem

This is a discussion on long long array problem within the C Programming forums, part of the General Programming Boards category; I perfer that the result is "0xFFFFFFFFFFFCCFCC" but in face, the result is "0xFFFCCFCC"? any bugs in my program? Code: ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    2

    Arrow long long array problem

    I perfer that the result is "0xFFFFFFFFFFFCCFCC"
    but in face, the result is "0xFFFCCFCC"?
    any bugs in my program?




    Code:
    #include <stdio.h>
    int    main(void)
    {
        int f;
        long long tempdata;
        long long* ptable;
    
    
    
    
         long long table [16]=
          {
          0xFFFFFFFFFFFCCFCC, //2>
          0xCCCCCCCCCCCCCCCC,
          0xCCCCCCCCCCCCCCCC,
          0xCCCCCCCCCCCCCCCC,
          0xCCCCCCCCCCCCCCCC,
          0xCCCCCCCCCCCCCCCC,
          0xCCCCCCCCCCCCCCCC,
          0xCCCCCCCCCCCCCCCC,
          0xCCCCCCCCCCCCCCCC,
          0xCCCCCCCCCCCCCCCC,
          0xCCCCCCCCCCCCCCCC,
          0xCCCCCCCCCCCCCCCC,
          0xCCCCCCCCCCCCCCCC,
          0xCCCCCCCCCCCCCCCC,
          0xCCCCCCCCCCCCCCCC,
          0xCCCCCCCCCCCCCCCC,    //1
          };
    
    
    
    
    
    
        f=0;
        ptable = table;
        tempdata = *(ptable+(f*256)+(0*16)+0);
        printf("result= %x",tempdata);
        return 0;
    
    
    }

  2. #2
    Registered User
    Join Date
    Mar 2010
    Posts
    535
    The printf specifier "%x" is used to print an int in hex. Since you're using long long at all I assume "int" is smaller than "long long" on your platform, probably 32 bits.

    Using "%llx" should work with most compilers, including GCC. MSVC uses something different, from memory it is "%I64x"

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    1) you need to use printf("result = %llx", tempdata); for 64 bit values

    2) if f is ever anything but 0 you are going to cause an integer overflow, which will most likely not be caught because of the lack of runtime checking in C.

  4. #4
    Registered User
    Join Date
    Nov 2011
    Posts
    2
    Quote Originally Posted by smokeyangel View Post
    The printf specifier "%x" is used to print an int in hex. Since you're using long long at all I assume "int" is smaller than "long long" on your platform, probably 32 bits.

    Using "%llx" should work with most compilers, including GCC. MSVC uses something different, from memory it is "%I64x"
    worked! thankyou

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 04-23-2011, 08:40 PM
  2. Replies: 1
    Last Post: 10-11-2010, 01:53 AM
  3. Conver long to 8 byte array and back to long
    By plopes in forum C Programming
    Replies: 3
    Last Post: 04-01-2009, 12:39 AM
  4. unsigned long long to string conversion
    By Wiretron in forum C++ Programming
    Replies: 6
    Last Post: 12-21-2007, 03:02 AM
  5. STLport with MingW - Long Long error on project build
    By Mario F. in forum C++ Programming
    Replies: 2
    Last Post: 08-21-2006, 08:55 AM

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