Is it standard and practical to use long long types?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matt

    Is it standard and practical to use long long types?

    Hi folks. Can you help with some questions?

    I gather that some types supported by g++ are nonstandard but have been
    proposed as standards.

    Are the long long and unsigned long long types still under consideration
    for the ANSI C and C++ standards? Are they likely to be accepted into
    the standards?

    Which compilers support those types, and which do not?

    In a general practical sense, is portability impaired for programs that
    use those types?

    Is there any good literature on standard techniques related to word size
    and portability?
    _______________ _________
    keywords: gnu gcc g++ borland turbo visual microsoft intel ISO ANSI
    compiler long long C C++ language standard

  • Kevin Goodsell

    #2
    Re: Is it standard and practical to use long long types?

    Matt wrote:[color=blue]
    > Hi folks. Can you help with some questions?[/color]

    Cross-posting to comp.lang.c and comp.lang.c++ is rarely the right thing
    to do. While related, these languages are different enough that answers
    for one frequently don't apply to the other.
    [color=blue]
    >
    > I gather that some types supported by g++ are nonstandard but have been
    > proposed as standards.
    >
    > Are the long long and unsigned long long types still under consideration
    > for the ANSI C and C++ standards? Are they likely to be accepted into
    > the standards?[/color]

    long long (along with its variants) was added to C with the 1999 ISO
    standard. C++ had not been updated with new features since 1998 (a 2003
    update corrected and clarified the existing standard, but added nothing
    new), and does not include long long. I don't know the details, but I'm
    sure it has been discussed and may still be being discussed for
    addition. I'd be surprised if it was not included in the next version of
    the C++ standard.
    [color=blue]
    >
    > Which compilers support those types, and which do not?[/color]

    C99 compilers do. Other C and C++ compilers do not, unless through
    extensions.
    [color=blue]
    >
    > In a general practical sense, is portability impaired for programs that
    > use those types?[/color]

    I would say so. C99 support is rather narrow at the moment.
    [color=blue]
    >
    > Is there any good literature on standard techniques related to word size
    > and portability?[/color]

    I don't understand this question.

    -Kevin
    --
    My email address is valid, but changes periodically.
    To contact me please use the address from a recent posting.

    Comment

    • Malcolm

      #3
      Re: Is it standard and practical to use long long types?


      "Matt" <matt@themattfe lla.zzzz.com> wrote in message[color=blue]
      >
      > Are the long long and unsigned long long types still under
      > consideration for the ANSI C and C++ standards? Are they likely
      > to be accepted into the standards?
      >[/color]
      Traditionally an int is the size of a register, and registers can be used
      either to hold addresses or data, so void * is also the same size as an int.
      That rule of thumb is breaking down with 64-bit architectures, because
      integers usually represent real numbers (say, the number of employees in a
      company) and there are only a few cases where you need a number bigger than
      4 billion.
      long long looks like the most likely convention to emerge for the 64-bit
      type. However it will be a long time before 32-bit architectures become
      rare, or long long becomes so entrenched that they are forced to support it.[color=blue]
      >
      > Is there any good literature on standard techniques related to word > size[/color]
      and portability?[color=blue]
      >[/color]
      Not that I know of. The main reason for using a 64-bit type is to represent
      a size of memory, in which case you should use size_t. Just occasionally you
      will need 64 bits for another purpose (eg give the entire population of the
      world an id number). In that case there is no neat solution if the target
      compiler won't support 64-bit types - you will have to define a structure
      and write your own arithmetical routines. (In C++ it is easier because you
      can wrap into a class). typedefing long long is probably a good idea if you
      think this might happen.


      Comment

      • Kevin Goodsell

        #4
        Re: Is it standard and practical to use long long types?

        Malcolm wrote:[color=blue]
        > "Matt" <matt@themattfe lla.zzzz.com> wrote in message
        >[color=green]
        >>Are the long long and unsigned long long types still under
        >>considerati on for the ANSI C and C++ standards? Are they likely
        >>to be accepted into the standards?
        >>[/color]
        >
        > Traditionally an int is the size of a register,[/color]

        Not on 8-bit machines. It's a recommendation, not a requirement.

        -Kevin
        --
        My email address is valid, but changes periodically.
        To contact me please use the address from a recent posting.

        Comment

        • Martin Ambuhl

          #5
          Re: Is it standard and practical to use long long types?

          Matt wrote:

          [color=blue]
          > Are the long long and unsigned long long types still under consideration
          > for the ANSI C and C++ standards? Are they likely to be accepted into
          > the standards?[/color]

          The C standard has included [signed | unsigned] long long now into its
          4th year.

          Follow-ups set to comp.lang.c.

          Comment

          • Matt

            #6
            Re: Is it standard and practical to use long long types?

            Kevin Goodsell wrote:[color=blue]
            > Matt wrote:[/color]
            [color=blue][color=green]
            >> Is there any good literature on standard techniques related to word
            >> size and portability?[/color]
            >
            >
            > I don't understand this question.
            >
            > -Kevin[/color]

            Oh. Uh, well, people have to deal with the fact that for a given
            numerical type, different compilers have different precisions for the
            given type. They want the same code to work the same with all or many
            compilers. I am looking for descriptions of standard techniques for
            doing that.

            Comment

            • Kevin Goodsell

              #7
              Re: Is it standard and practical to use long long types?

              Matt wrote:[color=blue]
              >
              > Oh. Uh, well, people have to deal with the fact that for a given
              > numerical type, different compilers have different precisions for the
              > given type. They want the same code to work the same with all or many
              > compilers. I am looking for descriptions of standard techniques for
              > doing that.
              >[/color]

              Well, the general technique is to know the required minimum ranges of
              the types and write code that doesn't rely on anything beyond those
              ranges. So if I need a variable that might exceed 32,767, I don't use an
              int. In many cases, additional precision beyond what is needed is not
              harmful, so choosing something guaranteed to be "wide enough" works just
              fine.

              When people have problems with the differences in precision that
              different implementations may use, it's usually because they want to do
              something that relies on variables using a particular representation and
              size. For example, writing a value out to a file as raw bits, and
              reading it back in later. The simple answer to this problem is "don't do
              that". A file written that way isn't portable anyway. The right thing to
              do is to define your file format, and write your program so that it
              handles that format (by reading & writing byte-by-byte and
              reconstructing/deconstructing values as you go if necessary -- though
              differences in the size of a byte could potentially cause problems).

              -Kevin
              --
              My email address is valid, but changes periodically.
              To contact me please use the address from a recent posting.

              Comment

              • Matt

                #8
                Re: Is it standard and practical to use long long types?

                Kevin Goodsell wrote:[color=blue]
                > Matt wrote:
                >[color=green]
                >>
                >> Oh. Uh, well, people have to deal with the fact that for a given
                >> numerical type, different compilers have different precisions for the
                >> given type. They want the same code to work the same with all or many
                >> compilers. I am looking for descriptions of standard techniques for
                >> doing that.
                >>[/color]
                >
                > Well, the general technique is to know the required minimum ranges of
                > the types and write code that doesn't rely on anything beyond those
                > ranges.[/color]

                OMG. Is this my punishment for cross posting?

                Comment

                • Jack Klein

                  #9
                  Re: Is it standard and practical to use long long types?

                  On Tue, 13 Apr 2004 00:10:35 +0100, "Malcolm"
                  <malcolm@55bank .freeserve.co.u k> wrote in comp.lang.c:
                  [color=blue]
                  >
                  > "Matt" <matt@themattfe lla.zzzz.com> wrote in message[color=green]
                  > >
                  > > Are the long long and unsigned long long types still under
                  > > consideration for the ANSI C and C++ standards? Are they likely
                  > > to be accepted into the standards?
                  > >[/color]
                  > Traditionally an int is the size of a register, and registers can be used
                  > either to hold addresses or data, so void * is also the same size as an int.
                  > That rule of thumb is breaking down with 64-bit architectures, because
                  > integers usually represent real numbers (say, the number of employees in a
                  > company) and there are only a few cases where you need a number bigger than
                  > 4 billion.[/color]

                  The correspondence in size between ints and registers has been broken
                  in many, many platforms over the years, long before 64-bit
                  architectures (other than Cray, perhaps) existed.

                  The assumption that sizeof(void *) == sizeof(int) is horrible broken
                  and a crutch for the uninformed or lazy, always has been, and always
                  will be.

                  I was working today, and will be for the next few weeks, on a platform
                  with quite a decent C compiler where int has 16 bits and pointers have
                  32. Not "far" pointers, but all pointers. At the hardware level,
                  addresses have 32 bits and there is a 4Gb address space.

                  --
                  Jack Klein
                  Home: http://JK-Technology.Com
                  FAQs for
                  comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
                  comp.lang.c++ http://www.parashift.com/c++-faq-lite/
                  alt.comp.lang.l earn.c-c++

                  Comment

                  • Keith Thompson

                    #10
                    Re: Is it standard and practical to use long long types?

                    Matt <matt@themattfe lla.zzzz.com> writes:[color=blue]
                    > Kevin Goodsell wrote:[color=green]
                    > > Matt wrote:[/color]
                    >[color=green][color=darkred]
                    > >> Is there any good literature on standard techniques related to word
                    > >> size and portability?[/color]
                    > > I don't understand this question.
                    > > -Kevin[/color]
                    >
                    > Oh. Uh, well, people have to deal with the fact that for a given
                    > numerical type, different compilers have different precisions for the
                    > given type. They want the same code to work the same with all or many
                    > compilers. I am looking for descriptions of standard techniques for
                    > doing that.[/color]

                    I've redirected followups to comp.lang.c.

                    C99 provides a standard header, <stdint.h>, that provides typedefs for
                    a variety of exact-width, minimum-width, and "fastest" signed and
                    unsigned integer types.

                    If your compiler doesn't support <stdint.h>, it's easy to implement
                    for any C90 compiler (except that it may or may not support 64-bit
                    types). See Doug Gwyn's public-domain q8 library, available at
                    <http://www.lysator.liu .se/c/q8/>.

                    Many pre-C99 compilers support "long long" and "unsigned long long" as
                    an extension, though it's not certain that the corresponding printf
                    formats will be supported by the library.

                    --
                    Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
                    Schroedinger does Shakespeare: "To be *and* not to be"

                    Comment

                    • jacob navia

                      #11
                      Re: Is it standard and practical to use long long types?

                      lcc-win32 supports long long. The non-standard
                      __int64
                      is supported to maintain compatibility with Microsoft Visual C.
                      It is a 64 bit integer type


                      Comment

                      • Ioannis Vranos

                        #12
                        Re: Is it standard and practical to use long long types?

                        "jacob navia" <jacob@jacob.re mcomp.fr> wrote in message
                        news:c5gs1j$cr9 $1@news-reader2.wanadoo .fr...[color=blue]
                        > lcc-win32 supports long long. The non-standard
                        > __int64
                        > is supported to maintain compatibility with Microsoft Visual C.
                        > It is a 64 bit integer type[/color]


                        Looking at the subject of your message, the answer is NO since there is not
                        such a thing as long long type in C++. Next time do not cross post among
                        irrelevant newsgroups, C & C++ are different languages.






                        Ioannis Vranos

                        Comment

                        • Matt

                          #13
                          Re: Is it standard and practical to use long long types?

                          Ioannis Vranos wrote:[color=blue]
                          > "jacob navia" <jacob@jacob.re mcomp.fr> wrote in message
                          > news:c5gs1j$cr9 $1@news-reader2.wanadoo .fr...
                          >[color=green]
                          >>lcc-win32 supports long long. The non-standard
                          >>__int64
                          >>is supported to maintain compatibility with Microsoft Visual C.
                          >>It is a 64 bit integer type[/color]
                          >
                          >
                          >
                          > Looking at the subject of your message, the answer is NO since there is not
                          > such a thing as long long type in C++. Next time do not cross post among
                          > irrelevant newsgroups, C & C++ are different languages.
                          >
                          >
                          >
                          >
                          >
                          >
                          > Ioannis Vranos
                          >[/color]

                          Next time reply to the same person you seem to be addressing.

                          Next time don't post using weirdo fonts.

                          Next time try to give a reply that is useful to somebody.

                          Comment

                          • Matt

                            #14
                            Re: Is it standard and practical to use long long types?

                            Kevin Goodsell wrote:[color=blue]
                            > Matt wrote:
                            >[color=green]
                            >> Hi folks. Can you help with some questions?[/color]
                            >
                            >
                            > Cross-posting to comp.lang.c and comp.lang.c++ is rarely the right thing
                            > to do. While related, these languages are different enough that answers
                            > for one frequently don't apply to the other.[/color]

                            I cross-posted because I am asking the questions about both languages.

                            Comment

                            • Joona I Palaste

                              #15
                              Re: Is it standard and practical to use long long types?

                              Matt <matt@themattfe lla.zzzz.com> scribbled the following
                              on comp.lang.c:[color=blue]
                              > Ioannis Vranos wrote:[color=green]
                              >> "jacob navia" <jacob@jacob.re mcomp.fr> wrote in message
                              >> news:c5gs1j$cr9 $1@news-reader2.wanadoo .fr...[color=darkred]
                              >>>lcc-win32 supports long long. The non-standard
                              >>>__int64
                              >>>is supported to maintain compatibility with Microsoft Visual C.
                              >>>It is a 64 bit integer type[/color]
                              >>
                              >> Looking at the subject of your message, the answer is NO since there is not
                              >> such a thing as long long type in C++. Next time do not cross post among
                              >> irrelevant newsgroups, C & C++ are different languages.[/color][/color]
                              [color=blue]
                              > Next time reply to the same person you seem to be addressing.[/color]
                              [color=blue]
                              > Next time don't post using weirdo fonts.[/color]
                              [color=blue]
                              > Next time try to give a reply that is useful to somebody.[/color]

                              Ioannis's post appeared just fine on my newsreader. Ioannis is using
                              a Greek locale on his newsreader, as apparent from the ISO-8859-7
                              charset in his NNTP headers, but his post does not use any characters
                              from that charset. Perhaps your own newsreader insists on using
                              "weirdo fonts" for any charset that is not ISO-8859-1?

                              --
                              /-- Joona Palaste (palaste@cc.hel sinki.fi) ------------- Finland --------\
                              \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
                              "You have moved your mouse, for these changes to take effect you must shut down
                              and restart your computer. Do you want to restart your computer now?"
                              - Karri Kalpio

                              Comment

                              Working...