scan: which format for a long long int

Discussion in 'C Programming' started by __frank__, Oct 29, 2005.

  1. __frank__

    __frank__ Guest

    Which format I have to use in scanf,
    to format a long long int (64bits int
    __int64 in MS VC++).
    Thanks in advance
    __frank__, Oct 29, 2005
    #1
    1. Advertising

  2. __frank__ <> writes:
    > Which format I have to use in scanf,
    > to format a long long int (64bits int
    > __int64 in MS VC++).


    "%lld", if your library supports it. It's required by C99, but of
    course there was long long type in C90.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, Oct 29, 2005
    #2
    1. Advertising

  3. __frank__

    Michael Mair Guest

    __frank__ wrote:
    > Which format I have to use in scanf,
    > to format a long long int (64bits int
    > __int64 in MS VC++).
    > Thanks in advance


    "%lld" or "%lli".

    Note: The long long integer types are in the language since C99;
    AFAIK, MS VC will not fully support C99 even in their 2005 Studio.
    At least in VC++6, the semantics of the 64 bit types were partially
    broken.
    If the above format does not work, you have a 64 bit type as an
    implementation specific extension; the format should be specified
    in the online help. Otherwise, you may have to ask in a newsgroup
    or forum where your implementation is topical.

    BTW: If you try to keep your code conforming, you can #define
    the appropriate integer conversion format strings and work with
    them like that:

    #if (defined __STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    # define MY_SLLFORMAT "%lld"
    # define MY_ULLFORMAT "%llu"
    #elif ...... /* ask for your implementation */
    ...../* Define your implementation specific MY_SLLFORMAT etc here */
    #else
    # error Cannot define an appropriate 64 bit integer format
    #end

    .....
    printf("Tit (" MY_SLLFORMAT ") for tat\n", mylonglongvar);


    Cheers
    Michael
    --
    E-Mail: Mine is an /at/ gmx /dot/ de address.
    Michael Mair, Oct 29, 2005
    #3
  4. __frank__

    Michael Mair Guest

    Keith Thompson wrote:
    > __frank__ <> writes:
    >
    >>Which format I have to use in scanf,
    >>to format a long long int (64bits int
    >>__int64 in MS VC++).

    >
    >
    > "%lld", if your library supports it. It's required by C99, but of
    > course there was long long type in C90.

    ^
    no

    Cheers
    Michael
    --
    E-Mail: Mine is an /at/ gmx /dot/ de address.
    Michael Mair, Oct 29, 2005
    #4
  5. Michael Mair <> writes:
    > Keith Thompson wrote:
    >> __frank__ <> writes:
    >>
    >>>Which format I have to use in scanf,
    >>>to format a long long int (64bits int
    >>>__int64 in MS VC++).

    >> "%lld", if your library supports it. It's required by C99, but of
    >> course there was long long type in C90.

    > ^
    > no


    Whoops! Thanks.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, Oct 29, 2005
    #5
  6. __frank__

    Jordan Abel Guest

    On 2005-10-29, Michael Mair <> wrote:
    > __frank__ wrote:
    >> Which format I have to use in scanf,
    >> to format a long long int (64bits int
    >> __int64 in MS VC++).
    >> Thanks in advance

    >
    > "%lld" or "%lli".
    >
    > Note: The long long integer types are in the language since C99;
    > AFAIK, MS VC will not fully support C99 even in their 2005 Studio.
    > At least in VC++6, the semantics of the 64 bit types were partially
    > broken.
    > If the above format does not work, you have a 64 bit type as an
    > implementation specific extension; the format should be specified
    > in the online help. Otherwise, you may have to ask in a newsgroup
    > or forum where your implementation is topical.
    >
    > BTW: If you try to keep your code conforming, you can #define
    > the appropriate integer conversion format strings and work with
    > them like that:
    >
    > #if (defined __STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    > # define MY_SLLFORMAT "%lld"
    > # define MY_ULLFORMAT "%llu"
    > #elif ...... /* ask for your implementation */
    > ..../* Define your implementation specific MY_SLLFORMAT etc here */
    > #else
    > # error Cannot define an appropriate 64 bit integer format
    > #end
    >
    > ....
    > printf("Tit (" MY_SLLFORMAT ") for tat\n", mylonglongvar);
    >
    >
    > Cheers
    > Michael


    Usually when defining a macro for a format specifier you don't want
    to include the % sign, so as to allow the user to include field
    widths and so on

    for example

    #define PRIdLLONG "lld"
    #define PRIuLLONG "llu"

    printf("Here's an example with a field width: %10"PRIdLLONG"\n", var);


    [i don't know if the entire PRI*/SCN* set of identifiers are
    reserved if inttypes.h is included - however if his system has
    inttypes.h he should probably be using the types defined therein
    instead]
    Jordan Abel, Oct 29, 2005
    #6
  7. __frank__

    kaikai Guest

    __frank__ 写é“:

    > Which format I have to use in scanf,
    > to format a long long int (64bits int
    > __int64 in MS VC++).
    > Thanks in advance

    In MS VC++, '__int64' read by this way
    __int64 i;
    scanf("%I64d", &i);
    kaikai, Oct 29, 2005
    #7
  8. "kaikai" <> writes:
    > __frank__ 写é“:
    >> Which format I have to use in scanf,
    >> to format a long long int (64bits int
    >> __int64 in MS VC++).
    >> Thanks in advance

    > In MS VC++, '__int64' read by this way
    > __int64 i;
    > scanf("%I64d", &i);


    And *only* (as far as I know) in MS VC++. "%I64d" is non-standard and
    non-portable. Writing non-portable code is sometimes necessary, of
    course.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, Oct 29, 2005
    #8
  9. __frank__

    Michael Mair Guest

    Jordan Abel wrote:
    > On 2005-10-29, Michael Mair <> wrote:
    >
    >>__frank__ wrote:
    >>
    >>>Which format I have to use in scanf,
    >>>to format a long long int (64bits int
    >>>__int64 in MS VC++).
    >>>Thanks in advance

    >>
    >>"%lld" or "%lli".
    >>
    >>Note: The long long integer types are in the language since C99;
    >>AFAIK, MS VC will not fully support C99 even in their 2005 Studio.
    >>At least in VC++6, the semantics of the 64 bit types were partially
    >>broken.
    >>If the above format does not work, you have a 64 bit type as an
    >>implementation specific extension; the format should be specified
    >>in the online help. Otherwise, you may have to ask in a newsgroup
    >>or forum where your implementation is topical.
    >>
    >>BTW: If you try to keep your code conforming, you can #define
    >>the appropriate integer conversion format strings and work with
    >>them like that:
    >>
    >>#if (defined __STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    >># define MY_SLLFORMAT "%lld"
    >># define MY_ULLFORMAT "%llu"
    >>#elif ...... /* ask for your implementation */
    >>..../* Define your implementation specific MY_SLLFORMAT etc here */
    >>#else
    >># error Cannot define an appropriate 64 bit integer format
    >>#end
    >>
    >>....
    >> printf("Tit (" MY_SLLFORMAT ") for tat\n", mylonglongvar);
    >>

    >
    > Usually when defining a macro for a format specifier you don't want
    > to include the % sign, so as to allow the user to include field
    > widths and so on
    >
    > for example
    >
    > #define PRIdLLONG "lld"
    > #define PRIuLLONG "llu"
    >
    > printf("Here's an example with a field width: %10"PRIdLLONG"\n", var);


    Thank you -- I did not think of this at that moment

    Cheers
    Michael
    --
    E-Mail: Mine is an /at/ gmx /dot/ de address.
    Michael Mair, Nov 1, 2005
    #9
  10. __frank__

    Guest

    Keith Thompson wrote:
    > "kaikai" <> writes:
    > > __frank__ 写é“:
    > >> Which format I have to use in scanf,
    > >> to format a long long int (64bits int
    > >> __int64 in MS VC++).
    > >> Thanks in advance

    > > In MS VC++, '__int64' read by this way
    > > __int64 i;
    > > scanf("%I64d", &i);

    >
    > And *only* (as far as I know) in MS VC++. "%I64d" is non-standard and
    > non-portable. Writing non-portable code is sometimes necessary, of
    > course.


    It is also supported by WATCOM C/C++, Borland C, and the Alpha
    compiler. This, presumably, is why C99 included stdint.h, and
    inttypes.h which includes abstractions for all these things.

    The only problem, of course, is that nobody seriously supports C99. So
    as a stop gap, you can use pstdint.h available here:

    http://www.pobox.com/~qed/pstdint.h

    This file can be used by older compilers that don't have even partial
    support for C99, and possible don't support 64 bit integers at all (you
    can test for this with a #ifdef INT64_MAX in your code.)

    This file includes a slightly different abstraction for print modifiers
    than inttypes.h -> The macro PRINTF_INT64_MODIFIER is used to specify
    the 64bit prefix for the integer formats. So:

    "%" PRINTF_INT64_MODIFIER "d"

    is (usually) the same as "%lld" or "%I64d" depending on which compiler
    you are using.

    --
    Paul Hsieh
    http://www.pobox.com/~qed/
    http://bstring.sf.net/
    , Nov 1, 2005
    #10
  11. Jordan Abel a écrit :
    > Usually when defining a macro for a format specifier you don't want
    > to include the % sign, so as to allow the user to include field
    > widths and so on


    Good point. Well noted.

    --
    C is a sharp tool
    Emmanuel Delahaye, Nov 1, 2005
    #11
  12. Keith Thompson a écrit :
    > And *only* (as far as I know) in MS VC++. "%I64d" is non-standard and
    > non-portable. Writing non-portable code is sometimes necessary, of
    > course.


    The question is not about the compiler or the IDE, but about the
    library. If your linker uses a library that loads the MSVCRT DLL, you
    are cooked. (VC++6, of course, but also Dev-C++ and more generally mingw
    based IDEs)

    --
    C is a sharp tool
    Emmanuel Delahaye, Nov 1, 2005
    #12
  13. __frank__

    Greg Comeau Guest

    In article <>,
    <> wrote:
    >Keith Thompson wrote:
    >> "kaikai" <> writes:
    >> > __frank__ =E5=86=99=E9=81=93=EF=BC=9A
    >> >> Which format I have to use in scanf,
    >> >> to format a long long int (64bits int
    >> >> __int64 in MS VC++).
    >> >> Thanks in advance
    >> > In MS VC++, '__int64' read by this way
    >> > __int64 i;
    >> > scanf("%I64d", &i);

    >>
    >> And *only* (as far as I know) in MS VC++. "%I64d" is non-standard and
    >> non-portable. Writing non-portable code is sometimes necessary, of
    >> course.

    >
    >It is also supported by WATCOM C/C++, Borland C, and the Alpha
    >compiler. This, presumably, is why C99 included stdint.h, and
    >inttypes.h which includes abstractions for all these things.
    >
    >The only problem, of course, is that nobody seriously supports C99.


    Comeau and Dinkumware do. The industry is another story.
    Comeau and Dinkumware also support MSisms well too.
    --
    Greg Comeau / Celebrating 20 years of Comeauity!
    Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
    World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
    Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
    Greg Comeau, Nov 1, 2005
    #13
  14. __frank__

    Jalapeno Guest

    Greg Comeau wrote:
    > In article <>,
    > <> wrote:
    > >
    > >The only problem, of course, is that nobody seriously supports C99.

    >
    > Comeau and Dinkumware do. The industry is another story.
    > Comeau and Dinkumware also support MSisms well too.


    IBM does too for its z/OS mainframe C

    http://publibz.boulder.ibm.com/cgi-.../FRONT_3.2.4?SHELF=CBCBS160&DT=20050628150638


    +------------------------------------------------------------------------------+



    z/OS XL C compiler specific features

    In addition to the features common to z/OS XL C and XL C++, the z/OS XL
    C compiler provides you with the following capabilities:


    The ability to write portable code that supports the following
    standards:

    | ISO/IEC 9899:1999 <-----<< isn't this C99?

    ANSI/ISO 9899:1990[1992] (formerly ANSI X3.159-1989 C)

    X/Open Specification Programming Languages, Issue 3, Common Usage C

    FIPS-160


    System programming capabilities, which allow you to use z/OS XL C in
    place of assembler

    Extensions of the standard definitions of the C language to provide
    programmers with support for the z/OS environment, such as fixed-point
    (packed) decimal data support
    Jalapeno, Nov 1, 2005
    #14
  15. __frank__

    Greg Comeau Guest

    In article <>,
    Jalapeno <> wrote:
    >Greg Comeau wrote:
    >> In article <>,
    >> <> wrote:
    >> >
    >> >The only problem, of course, is that nobody seriously supports C99.

    >>
    >> Comeau and Dinkumware do. The industry is another story.
    >> Comeau and Dinkumware also support MSisms well too.

    >
    >IBM does too for its z/OS mainframe C
    >...
    >| ISO/IEC 9899:1999 <-----<< isn't this C99?


    Yes. I've posted years ago which compilers support and/or
    claim to support C99; those posts should be googleable. The point
    is still that the industry is not doing a wideapread adoption
    of it. I still believe it will be C++ which will popularize C99,
    oddly enough, and perhaps not for the better.
    --
    Greg Comeau / Celebrating 20 years of Comeauity!
    Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
    World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
    Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
    Greg Comeau, Nov 1, 2005
    #15
  16. On Sat, 29 Oct 2005 09:51:23 +0000 (UTC), Jordan Abel
    <> wrote:
    <snip>
    > > BTW: If you try to keep your code conforming, you can #define
    > > the appropriate integer conversion format strings and work with
    > > them like that:
    > >
    > > #if (defined __STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    > > # define MY_SLLFORMAT "%lld"
    > > # define MY_ULLFORMAT "%llu"
    > > #elif ...... /* ask for your implementation */
    > > ..../* Define your implementation specific MY_SLLFORMAT etc here */
    > > #else
    > > # error Cannot define an appropriate 64 bit integer format
    > > #end


    > Usually when defining a macro for a format specifier you don't want
    > to include the % sign, so as to allow the user to include field
    > widths and so on
    >
    > for example
    >
    > #define PRIdLLONG "lld"
    > #define PRIuLLONG "llu"
    >
    > printf("Here's an example with a field width: %10"PRIdLLONG"\n", var);
    >
    >
    > [i don't know if the entire PRI*/SCN* set of identifiers are
    > reserved if inttypes.h is included - however if his system has
    > inttypes.h he should probably be using the types defined therein
    > instead]


    They ({PRI,SCN}[a-zX].*) are; 7.26.4.

    - David.Thompson1 at worldnet.att.net
    Dave Thompson, Nov 7, 2005
    #16
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Schnoffos
    Replies:
    2
    Views:
    1,189
    Martien Verbruggen
    Jun 27, 2003
  2. Hal Styli
    Replies:
    14
    Views:
    1,604
    Old Wolf
    Jan 20, 2004
  3. Daniel Rudy

    unsigned long long int to long double

    Daniel Rudy, Sep 19, 2005, in forum: C Programming
    Replies:
    5
    Views:
    1,161
    Peter Shaggy Haywood
    Sep 20, 2005
  4. pereges

    Promoting unsigned long int to long int

    pereges, Jun 30, 2008, in forum: C Programming
    Replies:
    112
    Views:
    2,017
    David Thompson
    Jul 28, 2008
  5. veryhotsausage
    Replies:
    1
    Views:
    1,766
    veryhotsausage
    Jul 4, 2008
Loading...

Share This Page