Like Tree3Likes
  • 1 Post By stahta01
  • 1 Post By Codeplug
  • 1 Post By jimblumberg

'long long' type and printf() (on AIX 5.3)

This is a discussion on 'long long' type and printf() (on AIX 5.3) within the C Programming forums, part of the General Programming Boards category; I am recently start in new company, they works on AIX v5.3 UNIX. Trying some C-coding I have found that ...

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    4

    'long long' type and printf() (on AIX 5.3)

    I am recently start in new company, they works on AIX v5.3 UNIX.
    Trying some C-coding I have found that I am not able to print the 'long long int' type variables.
    I have tried '%ll %L %LL %q' - no one is printing the #LL

    Surprizingly, I can not access C-printf manual here, nor to find it on internet (related to AIX)

    Most interesting that the #LL is accepted and processed well, but no way to print it

    Maybe I shoud specify for 'cc', some options?
    Maybe some specific include should be done with redefined or advansed 'printf()'?

    Here is an example of my tryes:
    Code:
    int main()
    {
       int  p1, p2, n1,n2,d1,d2;
       long long int lln=987654321000LL,
                     lld=876543210000LL, llr;
       llr=lln-lld;
       p1=llr/100000; p2=llr%p1;
       n1=lln/100000; n2=lln%n1;
       d1=lld/100000; d2=lld%d1;
       printf("The result of calculating #LL: (%d%d) - (%d%d) = (%d%d)\n",
               (int)(lln/10000LL), 1000, (int)(lld/100000LL), 10000, p1,p2 );
       printf("another try to print: %d,%05d; %d,%05d; %d,%05d\n",p1,p2,n1,n2,d1,d2);
       
       printf("Trying to print 'long long' type"
              "\n - by L:  %L"
              "\n - by LL: %LL"
              "\n - by q:  %q"
              "\n - by ll: %ll"
              "\n - by dll: %dll"
              "\n - by d:  %d"
              "\n - bi i:  %i\n", llr+1LL, llr+2LL, llr+3LL,llr+4LL, llr+5LL,llr+6LL,llr+7LL);
        printf("binary for -558038695: %s\n",b_prn(-558038695,sizeof(int)) );
              
      return 0;
    }
    
    /* results: 
    The result of calculating #LL: (987654321000) - (876543210000) = (111111111000)
    another try to print: 1111111,11000; 9876543,21000; 8765432,10000
    Trying to print 'long long' type
     - by L:
     - by LL:
     - by q:  q
     - by ll:
     - by dll: 25ll
     - by d:  -558038695
     - bi i:  25
    
    binary for -558038695: 11011110101111010000000101011001
    
    */
    So, it shows that the 'long long' variables processed well, but to present it to printf() I do not know a specifier.

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    2,372
    Code:
    #include <inttypes.h>
    See if the above header works.

    If yes, then use the correct MACRO to print.

    <inttypes.h>

    Tim S.
    alex5161 likes this.

  3. #3

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    2,564
    This seems to be the printf() documentation for AIX. It looks like you have your printf specifier backwards, it should be "%lld" not "%dll".

    Jim
    alex5161 likes this.

  5. #5
    Registered User
    Join Date
    Mar 2010
    Posts
    4

    found: %lld works!

    OK, never mine: the specifier '%lld' works!

    Ohh!
    Thank you, guys!
    I did not see yet your replay and very appreciate it

    And special thanks for links!
    Very usefull!
    Last edited by alex5161; 12-16-2011 at 03:08 PM.

  6. #6
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,607
    I'm the winner - for AIX documentation link anyway

    >> #include <inttypes.h>
    FYI - Posix 2008 version is here (not that it's any different):
    <inttypes.h>

    Root link:
    The Open Group Base Specifications Issue 7

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 10-11-2010, 01:53 AM
  2. How to printf long long data?
    By Mathsniper in forum C Programming
    Replies: 4
    Last Post: 12-09-2006, 12:32 PM
  3. printf not working with long type
    By that_guy1 in forum C Programming
    Replies: 2
    Last Post: 10-15-2005, 05:37 PM
  4. Displaying a 'long long' with printf
    By trinitrotoluene in forum C Programming
    Replies: 10
    Last Post: 12-28-2004, 12:32 AM
  5. Is long long int a valid Data Type
    By shiv_tech_quest in forum C Programming
    Replies: 2
    Last Post: 11-12-2003, 07:59 AM

Tags for this Thread


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