How widely supported is variable type 'long long int' ?

Discussion in 'C Programming' started by Charles Sullivan, Jun 22, 2007.

  1. I maintain/enhance some inherited FOSS software in C which has
    compiler options for quite a few different Unix-like operating
    systems, many of which I've never even heard of.

    It would be convenient (and for some things possibly necessary)
    to use long long integer and/or unsigned long long integer
    variables.

    How widely supported are these variable types? How long ago were
    they introduced? I notice they are not mentioned in K&R #2.

    Thanks for your help.

    Regards,
    Charles Sullivan
     
    Charles Sullivan, Jun 22, 2007
    #1
    1. Advertising

  2. On Jun 22, 2:55 pm, Charles Sullivan <> wrote:
    > I maintain/enhance some inherited FOSS software in C which has
    > compiler options for quite a few different Unix-like operating
    > systems, many of which I've never even heard of.
    >
    > It would be convenient (and for some things possibly necessary)
    > to use long long integer and/or unsigned long long integer
    > variables.
    >
    > How widely supported are these variable types? How long ago were
    > they introduced? I notice they are not mentioned in K&R #2.


    The long long type was officially introduced with the 1999 Standard,
    hence no mention of it in K&R2 which was published 10 years earlier.
    A number of compilers recognized and supported the type well before
    the new Standard was published, the "long long" name was selected
    based on consideration of this fact. While most compilers don't
    implement all of C99, a good many of those released in the last 10
    years do support long long. Some compilers may require an option to
    be set to enable support for long long so keep this in mind. As for
    whether it is widely enough supported for your needs, it would be a
    good idea to review the compilers you currently support and see if any
    of them don't support this type and go from there.

    Robert Gamble
     
    Robert Gamble, Jun 22, 2007
    #2
    1. Advertising

  3. Charles Sullivan <> writes:
    > I maintain/enhance some inherited FOSS software in C which has
    > compiler options for quite a few different Unix-like operating
    > systems, many of which I've never even heard of.
    >
    > It would be convenient (and for some things possibly necessary)
    > to use long long integer and/or unsigned long long integer
    > variables.
    >
    > How widely supported are these variable types? How long ago were
    > they introduced? I notice they are not mentioned in K&R #2.


    The types "long long" and "unsigned long long" were introduced in the
    ISO C standard of 1999. That standard is not yet widely implemented,
    though pieces of it are.

    Many, perhaps most, compilers support long long as an extension, but a
    compiler invoked in strict C90 mode will reject long long, even if it
    would accept it in a more relaxed mode.

    Why do you need "long long"? I suspect what you really need is a
    64-bit integer type; long long is guaranteed (in C99) to be at least
    64 bits, but it's entirely possible for long to be 64 bits in either
    C90 or C99.

    I think that some compilers may provide 64-bit integer types, but
    without using the name "long long" (Microsoft?).

    You might consider defining your own types, perhaps "long_long" and
    "unsigned_long_long", in an application-specific header; these would
    be typedefs for long long and unsigned long long where they're
    available, and for whatever other type is appropriate where they're
    not. You should be able to detect whether long long exists by
    checking "#ifdef LLONG_MAX" (after #include <limits.h>).

    --
    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."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Jun 22, 2007
    #3
  4. Charles Sullivan

    CBFalconer Guest

    Charles Sullivan wrote:
    >

    .... snip ...
    >
    > It would be convenient (and for some things possibly necessary)
    > to use long long integer and/or unsigned long long integer
    > variables.
    >
    > How widely supported are these variable types? How long ago were
    > they introduced? I notice they are not mentioned in K&R #2.


    Long long was introduced with C99. If you don't have a C99
    compliant compiler (and you probably don't) they won't work. They
    may be available on other systems as extensions, but will not be
    portable.

    --
    <http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
    <http://www.securityfocus.com/columnists/423>
    <http://www.aaxnet.com/editor/edit043.html>
    cbfalconer at maineline dot net


    --
    Posted via a free Usenet account from http://www.teranews.com
     
    CBFalconer, Jun 23, 2007
    #4
  5. CBFalconer <> writes:
    > Charles Sullivan wrote:
    >>

    > ... snip ...
    >>
    >> It would be convenient (and for some things possibly necessary)
    >> to use long long integer and/or unsigned long long integer
    >> variables.
    >>
    >> How widely supported are these variable types? How long ago were
    >> they introduced? I notice they are not mentioned in K&R #2.

    >
    > Long long was introduced with C99. If you don't have a C99
    > compliant compiler (and you probably don't) they won't work.


    Not true. I have a compiler that isn't C99 compliant, and it supports
    "long long" just fine (if I don't invoke it in strict C90 mode).

    If you do have a C99 compiler, long long will work.

    It does not follow from this that if you don't have a C99 compiler,
    long long won't work.

    > They may be available on other systems as extensions, but will not
    > be portable.


    Exactly. And in fact, "long long" is one of the most common
    extensions; I know of very few current C compilers that don't support
    it. It's not 100% portable, though; it's up to the OP to decide
    whether it's portable *enough*.

    --
    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."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Jun 23, 2007
    #5
  6. Charles Sullivan

    Ian Collins Guest

    Keith Thompson wrote:
    >
    > You might consider defining your own types, perhaps "long_long" and
    > "unsigned_long_long", in an application-specific header; these would
    > be typedefs for long long and unsigned long long where they're
    > available, and for whatever other type is appropriate where they're
    > not. You should be able to detect whether long long exists by
    > checking "#ifdef LLONG_MAX" (after #include <limits.h>).
    >

    Wouldn't it be better just to use the standard int64_t and uint64_t type
    names?

    --
    Ian Collins.
     
    Ian Collins, Jun 23, 2007
    #6
  7. Charles Sullivan

    user923005 Guest

    On Jun 22, 11:55 am, Charles Sullivan <> wrote:
    > I maintain/enhance some inherited FOSS software in C which has
    > compiler options for quite a few different Unix-like operating
    > systems, many of which I've never even heard of.
    >
    > It would be convenient (and for some things possibly necessary)
    > to use long long integer and/or unsigned long long integer
    > variables.
    >
    > How widely supported are these variable types? How long ago were
    > they introduced? I notice they are not mentioned in K&R #2.


    Older Microsoft compilers and the OpenVMS C and C++ compilers use:
    __int64 and unsigned __int64

    The current Microsoft compiler and recent GCC versions accept long
    long just fine.

    However, you can still run into speedbumps today. Some older, still
    running platforms do not have long long (e.g. OpenVMS VAX).
     
    user923005, Jun 23, 2007
    #7
  8. Ian Collins <> writes:
    > Keith Thompson wrote:
    >> You might consider defining your own types, perhaps "long_long" and
    >> "unsigned_long_long", in an application-specific header; these would
    >> be typedefs for long long and unsigned long long where they're
    >> available, and for whatever other type is appropriate where they're
    >> not. You should be able to detect whether long long exists by
    >> checking "#ifdef LLONG_MAX" (after #include <limits.h>).
    >>

    > Wouldn't it be better just to use the standard int64_t and uint64_t type
    > names?


    Probably, depending on what you need them for.

    If you need types that are exactly 64 bits wide, then yes, it makes
    sense to use int64_t and uint64_t (from <inttypes.h> if it exists, or
    defining them yourself if they don't).

    I think you're assuming that when the OP says "I need long long", he
    really means "I need a type that's exactly 64 bits wide". That
    assumption is likely to be correct (I've never heard of a C compiler
    where long long is anything other than exactly 64 bits) -- but that's
    not what "long long" means.

    Actually, I think the OP is dealing with some existing code that
    depends on long long. The appropriate course of action, particularly
    for implementations that don't support long long, probably depends on
    just how the code uses it.

    --
    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."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Jun 23, 2007
    #8
  9. Charles Sullivan

    CBFalconer Guest

    Keith Thompson wrote:
    > CBFalconer <> writes:
    >> Charles Sullivan wrote:
    >>>

    >> ... snip ...
    >>>
    >>> It would be convenient (and for some things possibly necessary)
    >>> to use long long integer and/or unsigned long long integer
    >>> variables.
    >>>
    >>> How widely supported are these variable types? How long ago were
    >>> they introduced? I notice they are not mentioned in K&R #2.

    >>
    >> Long long was introduced with C99. If you don't have a C99
    >> compliant compiler (and you probably don't) they won't work.

    >
    > Not true. I have a compiler that isn't C99 compliant, and it
    > supports "long long" just fine (if I don't invoke it in strict
    > C90 mode).


    You have a C90 compiler with enabled extensions.

    --
    <http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
    <http://www.securityfocus.com/columnists/423>
    <http://www.aaxnet.com/editor/edit043.html>
    cbfalconer at maineline dot net



    --
    Posted via a free Usenet account from http://www.teranews.com
     
    CBFalconer, Jun 23, 2007
    #9
  10. Charles Sullivan

    CBFalconer Guest

    Ian Collins wrote:
    > Keith Thompson wrote:
    >>
    >> You might consider defining your own types, perhaps "long_long"
    >> and "unsigned_long_long", in an application-specific header;
    >> these would be typedefs for long long and unsigned long long
    >> where they're available, and for whatever other type is
    >> appropriate where they're not. You should be able to detect
    >> whether long long exists by checking "#ifdef LLONG_MAX" (after
    >> #include <limits.h>).

    >
    > Wouldn't it be better just to use the standard int64_t and
    > uint64_t type names?


    They don't exist in C90. They may not exist in C99.

    --
    <http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
    <http://www.securityfocus.com/columnists/423>
    <http://www.aaxnet.com/editor/edit043.html>
    cbfalconer at maineline dot net



    --
    Posted via a free Usenet account from http://www.teranews.com
     
    CBFalconer, Jun 23, 2007
    #10
  11. Charles Sullivan

    Ian Collins Guest

    CBFalconer wrote:
    > Ian Collins wrote:
    >> Keith Thompson wrote:
    >>> You might consider defining your own types, perhaps "long_long"
    >>> and "unsigned_long_long", in an application-specific header;
    >>> these would be typedefs for long long and unsigned long long
    >>> where they're available, and for whatever other type is
    >>> appropriate where they're not. You should be able to detect
    >>> whether long long exists by checking "#ifdef LLONG_MAX" (after
    >>> #include <limits.h>).

    >> Wouldn't it be better just to use the standard int64_t and
    >> uint64_t type names?

    >
    > They don't exist in C90. They may not exist in C99.
    >

    So, I was suggesting using the standard names.

    --
    Ian Collins.
     
    Ian Collins, Jun 23, 2007
    #11
  12. Charles Sullivan

    Ian Collins Guest

    CBFalconer wrote:
    > Keith Thompson wrote:
    >> CBFalconer <> writes:
    >>> Charles Sullivan wrote:
    >>> ... snip ...
    >>>> It would be convenient (and for some things possibly necessary)
    >>>> to use long long integer and/or unsigned long long integer
    >>>> variables.
    >>>>
    >>>> How widely supported are these variable types? How long ago were
    >>>> they introduced? I notice they are not mentioned in K&R #2.
    >>> Long long was introduced with C99. If you don't have a C99
    >>> compliant compiler (and you probably don't) they won't work.

    >> Not true. I have a compiler that isn't C99 compliant, and it
    >> supports "long long" just fine (if I don't invoke it in strict
    >> C90 mode).

    >
    > You have a C90 compiler with enabled extensions.
    >

    Isn't that what Keith said ("if I don't invoke it in strict C90 mode")?

    --
    Ian Collins.
     
    Ian Collins, Jun 23, 2007
    #12
  13. CBFalconer <> writes:
    > Keith Thompson wrote:
    >> CBFalconer <> writes:
    >>> Charles Sullivan wrote:
    >>>>
    >>> ... snip ...
    >>>>
    >>>> It would be convenient (and for some things possibly necessary)
    >>>> to use long long integer and/or unsigned long long integer
    >>>> variables.
    >>>>
    >>>> How widely supported are these variable types? How long ago were
    >>>> they introduced? I notice they are not mentioned in K&R #2.
    >>>
    >>> Long long was introduced with C99. If you don't have a C99
    >>> compliant compiler (and you probably don't) they won't work.

    >>
    >> Not true. I have a compiler that isn't C99 compliant, and it
    >> supports "long long" just fine (if I don't invoke it in strict
    >> C90 mode).

    >
    > You have a C90 compiler with enabled extensions.


    Yes, of course -- which is entirely consistent with what I wrote, and
    contradicts your earlier statement.

    --
    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."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Jun 23, 2007
    #13
  14. Charles Sullivan

    CBFalconer Guest

    Ian Collins wrote:
    > CBFalconer wrote:
    >> Ian Collins wrote:
    >>> Keith Thompson wrote:
    >>>
    >>>> You might consider defining your own types, perhaps "long_long"
    >>>> and "unsigned_long_long", in an application-specific header;
    >>>> these would be typedefs for long long and unsigned long long
    >>>> where they're available, and for whatever other type is
    >>>> appropriate where they're not. You should be able to detect
    >>>> whether long long exists by checking "#ifdef LLONG_MAX" (after
    >>>> #include <limits.h>).
    >>>
    >>> Wouldn't it be better just to use the standard int64_t and
    >>> uint64_t type names?

    >>
    >> They don't exist in C90. They may not exist in C99.

    >
    > So, I was suggesting using the standard names.


    Then you run into problems when they are defined in that system.

    --
    <http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
    <http://www.securityfocus.com/columnists/423>
    <http://www.aaxnet.com/editor/edit043.html>
    cbfalconer at maineline dot net



    --
    Posted via a free Usenet account from http://www.teranews.com
     
    CBFalconer, Jun 23, 2007
    #14
  15. CBFalconer <> writes:
    > Ian Collins wrote:
    >> CBFalconer wrote:
    >>> Ian Collins wrote:
    >>>> Keith Thompson wrote:
    >>>>> You might consider defining your own types, perhaps "long_long"
    >>>>> and "unsigned_long_long", in an application-specific header;
    >>>>> these would be typedefs for long long and unsigned long long
    >>>>> where they're available, and for whatever other type is
    >>>>> appropriate where they're not. You should be able to detect
    >>>>> whether long long exists by checking "#ifdef LLONG_MAX" (after
    >>>>> #include <limits.h>).
    >>>>
    >>>> Wouldn't it be better just to use the standard int64_t and
    >>>> uint64_t type names?
    >>>
    >>> They don't exist in C90. They may not exist in C99.

    >>
    >> So, I was suggesting using the standard names.

    >
    > Then you run into problems when they are defined in that system.


    So you define them yourself if and only if they're not already defined.

    There's no good portable way in C to determine whether they're already
    defined, but there are a number of ways to do so outside the language
    (autoconf is one).

    --
    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."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Jun 23, 2007
    #15
  16. Charles Sullivan

    CBFalconer Guest

    Keith Thompson wrote:
    > CBFalconer <> writes:
    >> Ian Collins wrote:
    >>> CBFalconer wrote:
    >>>> Ian Collins wrote:
    >>>>> Keith Thompson wrote:
    >>>>>
    >>>>>> You might consider defining your own types, perhaps "long_long"
    >>>>>> and "unsigned_long_long", in an application-specific header;
    >>>>>> these would be typedefs for long long and unsigned long long
    >>>>>> where they're available, and for whatever other type is
    >>>>>> appropriate where they're not. You should be able to detect
    >>>>>> whether long long exists by checking "#ifdef LLONG_MAX" (after
    >>>>>> #include <limits.h>).
    >>>>>
    >>>>> Wouldn't it be better just to use the standard int64_t and
    >>>>> uint64_t type names?
    >>>>
    >>>> They don't exist in C90. They may not exist in C99.
    >>>
    >>> So, I was suggesting using the standard names.

    >>
    >> Then you run into problems when they are defined in that system.

    >
    > So you define them yourself if and only if they're not already
    > defined. There's no good portable way in C to determine whether
    > they're already defined, but there are a number of ways to do so
    > outside the language (autoconf is one).


    That's another matter entirely. What I suggest is trying VERY hard
    to stick to the normal brew of short, int, long.

    --
    <http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
    <http://www.securityfocus.com/columnists/423>
    <http://www.aaxnet.com/editor/edit043.html>
    cbfalconer at maineline dot net



    --
    Posted via a free Usenet account from http://www.teranews.com
     
    CBFalconer, Jun 24, 2007
    #16
  17. CBFalconer <> writes:
    > Keith Thompson wrote:
    >> CBFalconer <> writes:
    >>> Ian Collins wrote:
    >>>> CBFalconer wrote:
    >>>>> Ian Collins wrote:
    >>>>>> Keith Thompson wrote:
    >>>>>>> You might consider defining your own types, perhaps "long_long"
    >>>>>>> and "unsigned_long_long", in an application-specific header;
    >>>>>>> these would be typedefs for long long and unsigned long long
    >>>>>>> where they're available, and for whatever other type is
    >>>>>>> appropriate where they're not. You should be able to detect
    >>>>>>> whether long long exists by checking "#ifdef LLONG_MAX" (after
    >>>>>>> #include <limits.h>).
    >>>>>>
    >>>>>> Wouldn't it be better just to use the standard int64_t and
    >>>>>> uint64_t type names?
    >>>>>
    >>>>> They don't exist in C90. They may not exist in C99.
    >>>>
    >>>> So, I was suggesting using the standard names.
    >>>
    >>> Then you run into problems when they are defined in that system.

    >>
    >> So you define them yourself if and only if they're not already
    >> defined. There's no good portable way in C to determine whether
    >> they're already defined, but there are a number of ways to do so
    >> outside the language (autoconf is one).

    >
    > That's another matter entirely. What I suggest is trying VERY hard
    > to stick to the normal brew of short, int, long.


    Sure, if you ignore the OP's explicit requirement it's really easy.

    --
    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."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Jun 24, 2007
    #17
  18. Charles Sullivan

    Barry Guest

    "Keith Thompson" <> wrote in message
    news:...
    > CBFalconer <> writes:
    >> Ian Collins wrote:
    >>> CBFalconer wrote:
    >>>> Ian Collins wrote:
    >>>>> Keith Thompson wrote:
    >>>>>> You might consider defining your own types, perhaps "long_long"
    >>>>>> and "unsigned_long_long", in an application-specific header;
    >>>>>> these would be typedefs for long long and unsigned long long
    >>>>>> where they're available, and for whatever other type is
    >>>>>> appropriate where they're not. You should be able to detect
    >>>>>> whether long long exists by checking "#ifdef LLONG_MAX" (after
    >>>>>> #include <limits.h>).
    >>>>>
    >>>>> Wouldn't it be better just to use the standard int64_t and
    >>>>> uint64_t type names?
    >>>>
    >>>> They don't exist in C90. They may not exist in C99.
    >>>
    >>> So, I was suggesting using the standard names.

    >>
    >> Then you run into problems when they are defined in that system.

    >
    > So you define them yourself if and only if they're not already defined.
    >
    > There's no good portable way in C to determine whether they're already
    > defined, but there are a number of ways to do so outside the language
    > (autoconf is one).
    >


    <OT>
    Autoconf is also not portable. Nor reliable.
    </OT>
     
    Barry, Jun 24, 2007
    #18
  19. "Barry" <> writes:
    > "Keith Thompson" <> wrote in message
    > news:...

    [...]
    >> So you define them yourself if and only if they're not already defined.
    >>
    >> There's no good portable way in C to determine whether they're already
    >> defined, but there are a number of ways to do so outside the language
    >> (autoconf is one).
    >>

    >
    > <OT>
    > Autoconf is also not portable. Nor reliable.
    > </OT>


    I didn't mean to imply otherwise.

    --
    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."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Jun 24, 2007
    #19
  20. Re: How widely supported is variable type 'long long int' ? THANKS!!!

    On Fri, 22 Jun 2007 14:55:14 -0400, Charles Sullivan wrote:

    > I maintain/enhance some inherited FOSS software in C which has
    > compiler options for quite a few different Unix-like operating
    > systems, many of which I've never even heard of.
    >
    > It would be convenient (and for some things possibly necessary)
    > to use long long integer and/or unsigned long long integer
    > variables.
    >
    > How widely supported are these variable types? How long ago were
    > they introduced? I notice they are not mentioned in K&R #2.
    >
    > Thanks for your help.
    >
    > Regards,
    > Charles Sullivan


    Many thanks to all who responded. Your comments have been
    very useful.

    For those who wondered why I needed long longs:
    My app makes extensive use of unsigned long bitmaps and bitwise
    logic. Enhancements to the app occasionally require defining new
    bit positions and in some cases I'm getting close to running out.
    It would be far simpler to switch to unsigned long long than to
    reprogram to use multiple unsigned longs.

    Thanks again.

    Regards,
    Charles Sullivan
     
    Charles Sullivan, Jun 24, 2007
    #20
    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,252
    Martien Verbruggen
    Jun 27, 2003
  2. Hal Styli
    Replies:
    14
    Views:
    1,713
    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,248
    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,185
    David Thompson
    Jul 28, 2008
  5. veryhotsausage
    Replies:
    1
    Views:
    1,899
    veryhotsausage
    Jul 4, 2008
Loading...

Share This Page