unsigned long long

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Richard A. Huebner

    unsigned long long

    Is the unsigned long long primitive data type supported in ANSI
    standard C?

    I've tried using it a couple of times in standard C, but to no avail.
    I'm using both MS VIsual C++ 6, as well as the gcc compiler that comes
    with RedHat linux 9.

    If not, what data type will yield the largest unsigned integer for me?

    Thanks for your help,

    Rich


  • Joona I Palaste

    #2
    Re: unsigned long long

    Richard A. Huebner <encprof@yahoo. com> scribbled the following:[color=blue]
    > Is the unsigned long long primitive data type supported in ANSI
    > standard C?[/color]

    In C99, yes. In C90, no. Most current implementations of ANSI standard
    C are still C90.
    [color=blue]
    > I've tried using it a couple of times in standard C, but to no avail.
    > I'm using both MS VIsual C++ 6, as well as the gcc compiler that comes
    > with RedHat linux 9.[/color]
    [color=blue]
    > If not, what data type will yield the largest unsigned integer for me?[/color]

    unsigned long.

    --
    /-- Joona Palaste (palaste@cc.hel sinki.fi) ------------- Finland --------\
    \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
    "I wish someone we knew would die so we could leave them flowers."
    - A 6-year-old girl, upon seeing flowers in a cemetery

    Comment

    • Tom St Denis

      #3
      Re: unsigned long long


      "Joona I Palaste" <palaste@cc.hel sinki.fi> wrote in message
      news:borl51$lbd $1@oravannahka. helsinki.fi...[color=blue][color=green]
      > > I've tried using it a couple of times in standard C, but to no avail.
      > > I'm using both MS VIsual C++ 6, as well as the gcc compiler that comes
      > > with RedHat linux 9.[/color]
      >[color=green]
      > > If not, what data type will yield the largest unsigned integer for me?[/color]
      >
      > unsigned long.[/color]

      Actually GCC has supported "unsigned long long" for quite some time. MSVC
      supports "unsigned __int64" which is a 64-bit type..

      Tom


      Comment

      • Nudge

        #4
        Re: unsigned long long

        Richard A. Huebner wrote:[color=blue]
        > If not, what data type will yield the largest unsigned integer
        > for me?[/color]

        I don't know how to answer your question.

        uint64_t might be useful still?

        Comment

        • Joona I Palaste

          #5
          Re: unsigned long long

          Tom St Denis <tomstdenis@iah u.ca> scribbled the following:[color=blue]
          > "Joona I Palaste" <palaste@cc.hel sinki.fi> wrote in message
          > news:borl51$lbd $1@oravannahka. helsinki.fi...[color=green][color=darkred]
          >> > I've tried using it a couple of times in standard C, but to no avail.
          >> > I'm using both MS VIsual C++ 6, as well as the gcc compiler that comes
          >> > with RedHat linux 9.[/color]
          >>[color=darkred]
          >> > If not, what data type will yield the largest unsigned integer for me?[/color]
          >>
          >> unsigned long.[/color][/color]
          [color=blue]
          > Actually GCC has supported "unsigned long long" for quite some time. MSVC
          > supports "unsigned __int64" which is a 64-bit type..[/color]

          Yes, but hardly in ANSI standard C, or what?

          --
          /-- Joona Palaste (palaste@cc.hel sinki.fi) ------------- Finland --------\
          \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
          "Immanuel Kant but Genghis Khan."
          - The Official Graffitist's Handbook

          Comment

          • Tom St Denis

            #6
            Re: unsigned long long


            "Joona I Palaste" <palaste@cc.hel sinki.fi> wrote in message
            news:borm04$lnc $1@oravannahka. helsinki.fi...[color=blue]
            > Tom St Denis <tomstdenis@iah u.ca> scribbled the following:[color=green]
            > > "Joona I Palaste" <palaste@cc.hel sinki.fi> wrote in message
            > > news:borl51$lbd $1@oravannahka. helsinki.fi...[color=darkred]
            > >> > I've tried using it a couple of times in standard C, but to no avail.
            > >> > I'm using both MS VIsual C++ 6, as well as the gcc compiler that[/color][/color][/color]
            comes[color=blue][color=green][color=darkred]
            > >> > with RedHat linux 9.
            > >>
            > >> > If not, what data type will yield the largest unsigned integer for[/color][/color][/color]
            me?[color=blue][color=green][color=darkred]
            > >>
            > >> unsigned long.[/color][/color]
            >[color=green]
            > > Actually GCC has supported "unsigned long long" for quite some time.[/color][/color]
            MSVC[color=blue][color=green]
            > > supports "unsigned __int64" which is a 64-bit type..[/color]
            >
            > Yes, but hardly in ANSI standard C, or what?[/color]

            ANSI is old. I for one welcome our new ISO overlords.

            Tom


            Comment

            • Joona I Palaste

              #7
              Re: unsigned long long

              Tom St Denis <tomstdenis@iah u.ca> scribbled the following:[color=blue]
              > "Joona I Palaste" <palaste@cc.hel sinki.fi> wrote in message
              > news:borm04$lnc $1@oravannahka. helsinki.fi...[color=green]
              >> Tom St Denis <tomstdenis@iah u.ca> scribbled the following:[color=darkred]
              >> > "Joona I Palaste" <palaste@cc.hel sinki.fi> wrote in message
              >> > news:borl51$lbd $1@oravannahka. helsinki.fi...
              >> >> > I've tried using it a couple of times in standard C, but to no avail.
              >> >> > I'm using both MS VIsual C++ 6, as well as the gcc compiler that[/color][/color]
              > comes[color=green][color=darkred]
              >> >> > with RedHat linux 9.
              >> >>
              >> >> > If not, what data type will yield the largest unsigned integer for[/color][/color]
              > me?[color=green][color=darkred]
              >> >>
              >> >> unsigned long.[/color]
              >>[color=darkred]
              >> > Actually GCC has supported "unsigned long long" for quite some time.[/color][/color]
              > MSVC[color=green][color=darkred]
              >> > supports "unsigned __int64" which is a 64-bit type..[/color]
              >>
              >> Yes, but hardly in ANSI standard C, or what?[/color][/color]
              [color=blue]
              > ANSI is old. I for one welcome our new ISO overlords.[/color]

              I would think that the difference between the ANSI and ISO versions of
              the C standard is entirely bureaucratic and has no effect on the
              technical content.

              --
              /-- Joona Palaste (palaste@cc.hel sinki.fi) ------------- Finland --------\
              \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
              "'So called' means: 'There is a long explanation for this, but I have no
              time to explain it here.'"
              - JIPsoft

              Comment

              • Tom St Denis

                #8
                Re: unsigned long long


                "Joona I Palaste" <palaste@cc.hel sinki.fi> wrote in message
                news:bormbg$lut $1@oravannahka. helsinki.fi...[color=blue][color=green]
                > > ANSI is old. I for one welcome our new ISO overlords.[/color]
                >
                > I would think that the difference between the ANSI and ISO versions of
                > the C standard is entirely bureaucratic and has no effect on the
                > technical content.[/color]

                Be that as it may "unsigned long long" is part of ISOC AFAIK.

                Tom


                Comment

                • Joona I Palaste

                  #9
                  Re: unsigned long long

                  Tom St Denis <tomstdenis@iah u.ca> scribbled the following:[color=blue]
                  > "Joona I Palaste" <palaste@cc.hel sinki.fi> wrote in message
                  > news:bormbg$lut $1@oravannahka. helsinki.fi...[color=green][color=darkred]
                  >> > ANSI is old. I for one welcome our new ISO overlords.[/color]
                  >>
                  >> I would think that the difference between the ANSI and ISO versions of
                  >> the C standard is entirely bureaucratic and has no effect on the
                  >> technical content.[/color][/color]
                  [color=blue]
                  > Be that as it may "unsigned long long" is part of ISOC AFAIK.[/color]

                  ISO C99, Tom. Not ISO C90.

                  --
                  /-- Joona Palaste (palaste@cc.hel sinki.fi) ------------- Finland --------\
                  \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
                  "I am looking for myself. Have you seen me somewhere?"
                  - Anon

                  Comment

                  • Tom St Denis

                    #10
                    Re: unsigned long long


                    "Joona I Palaste" <palaste@cc.hel sinki.fi> wrote in message
                    news:bormg1$lut $2@oravannahka. helsinki.fi...[color=blue]
                    > Tom St Denis <tomstdenis@iah u.ca> scribbled the following:[color=green]
                    > > "Joona I Palaste" <palaste@cc.hel sinki.fi> wrote in message
                    > > news:bormbg$lut $1@oravannahka. helsinki.fi...[color=darkred]
                    > >> > ANSI is old. I for one welcome our new ISO overlords.
                    > >>
                    > >> I would think that the difference between the ANSI and ISO versions of
                    > >> the C standard is entirely bureaucratic and has no effect on the
                    > >> technical content.[/color][/color]
                    >[color=green]
                    > > Be that as it may "unsigned long long" is part of ISOC AFAIK.[/color]
                    >
                    > ISO C99, Tom. Not ISO C90.[/color]

                    Tom assumes we're dealing with the latest not the oldest.

                    Otherwise crack out some K&R !

                    Tom


                    Comment

                    • P.J. Plauger

                      #11
                      Re: unsigned long long

                      "Tom St Denis" <tomstdenis@iah u.ca> wrote in message
                      news:P1dsb.2348 $iD1.1109@news0 4.bloor.is.net. cable.rogers.co m...
                      [color=blue]
                      > "Joona I Palaste" <palaste@cc.hel sinki.fi> wrote in message
                      > news:bormbg$lut $1@oravannahka. helsinki.fi...[color=green][color=darkred]
                      > > > ANSI is old. I for one welcome our new ISO overlords.[/color]
                      > >
                      > > I would think that the difference between the ANSI and ISO versions of
                      > > the C standard is entirely bureaucratic and has no effect on the
                      > > technical content.[/color]
                      >
                      > Be that as it may "unsigned long long" is part of ISOC AFAIK.[/color]

                      The current ANSI standard for C is identical to the current ISO
                      standard for C, aka C99.

                      P.J. Plauger
                      Dinkumware, Ltd.



                      Comment

                      • Joe Wright

                        #12
                        Re: unsigned long long

                        Richard A. Huebner wrote:[color=blue]
                        >
                        > Is the unsigned long long primitive data type supported in ANSI
                        > standard C?
                        >
                        > I've tried using it a couple of times in standard C, but to no avail.
                        > I'm using both MS VIsual C++ 6, as well as the gcc compiler that comes
                        > with RedHat linux 9.
                        >
                        > If not, what data type will yield the largest unsigned integer for me?
                        >
                        > Thanks for your help,
                        >
                        > Rich[/color]

                        Try this.

                        /*
                        Sizes of various things in bits..
                        */
                        #include <stdio.h>
                        #include <limits.h>

                        int main(void) {
                        unsigned int a, b, c;
                        unsigned long long x, y, z;

                        c = -1;
                        b = 1 << (sizeof(int)*CH AR_BIT-1);
                        a = ~b;

                        z = -1;
                        y = 1LL << (sizeof(long long)*CHAR_BIT-1);
                        x = ~y;

                        printf("Size of void = %2lu bits\n", sizeof(void) *
                        CHAR_BIT);
                        printf("Size of char = %2lu bits\n", sizeof(char) *
                        CHAR_BIT);
                        printf("Size of short = %2lu bits\n", sizeof(short) *
                        CHAR_BIT);
                        printf("Size of int = %2lu bits\n", sizeof(int) *
                        CHAR_BIT);
                        printf("Size of long = %2lu bits\n", sizeof(long) *
                        CHAR_BIT);
                        printf("Size of long long = %2lu bits\n", sizeof(long long) *
                        CHAR_BIT);
                        printf("Size of int * = %2lu bits\n", sizeof(int *) *
                        CHAR_BIT);
                        printf("Size of char * = %2lu bits\n", sizeof(char *) *
                        CHAR_BIT);
                        printf("Size of void * = %2lu bits\n", sizeof(void *) *
                        CHAR_BIT);
                        printf("Size of float = %2lu bits\n", sizeof(float) *
                        CHAR_BIT);
                        printf("Size of double = %2lu bits\n", sizeof(double) *
                        CHAR_BIT);
                        printf("Size of long double = %2lu bits\n", sizeof(long double) *
                        CHAR_BIT);
                        printf("Max int = %11d\n", a);
                        printf("Min int = %11d\n", b);
                        printf("Max unsigned int = %11u\n", c);
                        printf("Max long long = %20lld\n", x);
                        printf("Min long long = %20lld\n", y);
                        printf("Max unsigned long long = %20llu\n", z);
                        return 0;
                        }

                        --
                        Joe Wright http://www.jw-wright.com
                        "Everything should be made as simple as possible, but not simpler."
                        --- Albert Einstein ---

                        Comment

                        • Eric Sosman

                          #13
                          Re: unsigned long long

                          Joe Wright wrote:[color=blue]
                          >
                          > Richard A. Huebner wrote:[color=green]
                          > >
                          > > Is the unsigned long long primitive data type supported in ANSI
                          > > standard C?
                          > >
                          > > I've tried using it a couple of times in standard C, but to no avail.
                          > > I'm using both MS VIsual C++ 6, as well as the gcc compiler that comes
                          > > with RedHat linux 9.
                          > >
                          > > If not, what data type will yield the largest unsigned integer for me?
                          > >
                          > > Thanks for your help,
                          > >
                          > > Rich[/color]
                          >
                          > Try this.
                          > [code snipped; see up-thread][/color]

                          I tried it, and the compiler said:

                          "foo.c", line 12: warning: integer overflow detected: op "<<"
                          "foo.c", line 19: cannot take sizeof void
                          cc: acomp failed for foo.c

                          --
                          Eric.Sosman@sun .com

                          Comment

                          • Richard Heathfield

                            #14
                            Re: unsigned long long

                            Joe Wright wrote:

                            <snip>
                            [color=blue]
                            > printf("Size of char = %2lu bits\n", sizeof(char) *
                            > CHAR_BIT);[/color]

                            Apart from Eric's comments, you may find it a good idea to cast the
                            expression sizeof(char) * CHAR_BIT to unsigned long before passing it to a
                            variadic function such as printf.

                            --
                            Richard Heathfield : binary@eton.pow ernet.co.uk
                            "Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
                            C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
                            K&R answers, C books, etc: http://users.powernet.co.uk/eton

                            Comment

                            • Joe Wright

                              #15
                              Re: unsigned long long

                              Eric Sosman wrote:[color=blue]
                              >
                              > Joe Wright wrote:[color=green]
                              > >
                              > > Richard A. Huebner wrote:[color=darkred]
                              > > >
                              > > > Is the unsigned long long primitive data type supported in ANSI
                              > > > standard C?
                              > > >
                              > > > I've tried using it a couple of times in standard C, but to no avail.
                              > > > I'm using both MS VIsual C++ 6, as well as the gcc compiler that comes
                              > > > with RedHat linux 9.
                              > > >
                              > > > If not, what data type will yield the largest unsigned integer for me?
                              > > >
                              > > > Thanks for your help,
                              > > >
                              > > > Rich[/color]
                              > >
                              > > Try this.
                              > > [code snipped; see up-thread][/color]
                              >
                              > I tried it, and the compiler said:
                              >
                              > "foo.c", line 12: warning: integer overflow detected: op "<<"
                              > "foo.c", line 19: cannot take sizeof void
                              > cc: acomp failed for foo.c
                              >[/color]
                              What was wrong? Should ..
                              y = 1LL << (sizeof(long long)*CHAR_BIT-1);
                              be
                              y = 1ULL << (sizeof(long long)*CHAR_BIT-1);
                              or something?
                              --
                              Joe Wright http://www.jw-wright.com
                              "Everything should be made as simple as possible, but not simpler."
                              --- Albert Einstein ---

                              Comment

                              Working...