data type of size 64 bits on a 32 bit processor

Discussion in 'C Programming' started by junky_fellow@yahoo.co.in, Mar 16, 2007.

  1. Guest

    Hi,

    I am using a gcc compiler for a 32 bit powerpc processor. When I
    look at the size of unsigned long long, it displays 8 bytes. I was
    wondering, how we can have a data type of 64 bits on a 32 bit
    processor ? Is there some problem with my compiler ?

    thanks for any help ...
    , Mar 16, 2007
    #1
    1. Advertising

  2. Tim Prince Guest

    wrote:
    > Hi,
    >
    > I am using a gcc compiler for a 32 bit powerpc processor. When I
    > look at the size of unsigned long long, it displays 8 bytes. I was
    > wondering, how we can have a data type of 64 bits on a 32 bit
    > processor ? Is there some problem with my compiler ?
    >

    Compilers implement wider types by coupling together shorter native data
    types where necessary. How do you think C got off the ground in the
    days of 8-bit computing?
    Tim Prince, Mar 16, 2007
    #2
    1. Advertising

  3. ziibrs Guest

    As in C99:

    long long and its unsigned counterpart unsigned long long are new
    types in C99. A long long variable shall have at least 64 bits.

    there is a long double with 96bits that also exists on 32bit machines

    in fact the xx-bit architecture does very little to do with variable
    sizes ( of course it is ment to be that int is as long as the memory
    address), because when storing variable in registers u can use more
    than one. I am not a specialist in hardware but as i understand in
    fact we have one long register that emulates smaller ones. And if wee
    need we can emuleate a 64-bit or even lager register to store data in.
    ziibrs, Mar 16, 2007
    #3
  4. Chris Dollin Guest

    wrote:

    > I am using a gcc compiler for a 32 bit powerpc processor. When I
    > look at the size of unsigned long long, it displays 8 bytes. I was
    > wondering, how we can have a data type of 64 bits on a 32 bit
    > processor ?


    Two words at a time.

    > Is there some problem with my compiler ?


    Not in this respect.

    --
    Chris "electric hedgehog" Dollin
    "It was the first really clever thing the King had said that day."
    /Alice in Wonderland/
    Chris Dollin, Mar 16, 2007
    #4
  5. "" wrote:
    >
    > Hi,
    >
    > I am using a gcc compiler for a 32 bit powerpc processor. When I
    > look at the size of unsigned long long, it displays 8 bytes. I was
    > wondering, how we can have a data type of 64 bits on a 32 bit
    > processor ? Is there some problem with my compiler ?


    What makes you think there is a "problem"? Just because a particular
    piece of hardware doesn't natively support N-bit integers doesn't
    mean the compiler can't supply software routines to handle them.

    --
    +-------------------------+--------------------+-----------------------+
    | Kenneth J. Brody | www.hvcomputer.com | #include |
    | kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
    +-------------------------+--------------------+-----------------------+
    Don't e-mail me at: <mailto:>
    Kenneth Brody, Mar 16, 2007
    #5
  6. On 16 Mar 2007 05:40:11 -0700, in comp.lang.c ,
    "" <> wrote:

    >Hi,
    >
    > I am using a gcc compiler for a 32 bit powerpc processor. When I
    >look at the size of unsigned long long, it displays 8 bytes. I was
    >wondering, how we can have a data type of 64 bits on a 32 bit
    >processor ?


    This isn't a C question.

    <OT>
    The width of the bus only restricts the amount of addressable space,
    not the size an object can be.

    For more info, read any history book about computing.
    </OT>
    --
    Mark McIntyre

    "Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are,
    by definition, not smart enough to debug it."
    --Brian Kernighan
    Mark McIntyre, Mar 16, 2007
    #6
  7. <> wrote in message
    > I am using a gcc compiler for a 32 bit powerpc processor. When I
    > look at the size of unsigned long long, it displays 8 bytes. I was
    > wondering, how we can have a data type of 64 bits on a 32 bit
    > processor ? Is there some problem with my compiler ?
    >
    > thanks for any help ...
    >

    Try the following

    register long long x;

    if the compiler claims to be able to store x in a register then I think
    you'd have legitimate grounds for complaint.

    --
    Free games and programming goodies.
    http://www.personal.leeds.ac.uk/~bgy1mm
    Malcolm McLean, Mar 16, 2007
    #7
  8. Ben Pfaff Guest

    "" <> writes:

    > I am using a gcc compiler for a 32 bit powerpc processor. When I
    > look at the size of unsigned long long, it displays 8 bytes. I was
    > wondering, how we can have a data type of 64 bits on a 32 bit
    > processor ? Is there some problem with my compiler ?


    How do you do arithmetic by hand on numbers with more than one
    digit? The computer can do multi-word arithmetic the same way.
    --
    "What is appropriate for the master is not appropriate for the novice.
    You must understand the Tao before transcending structure."
    --The Tao of Programming
    Ben Pfaff, Mar 16, 2007
    #8
  9. Ben Pfaff Guest

    "Malcolm McLean" <> writes:

    > <> wrote in message
    >> I am using a gcc compiler for a 32 bit powerpc processor. When I
    >> look at the size of unsigned long long, it displays 8 bytes. I was
    >> wondering, how we can have a data type of 64 bits on a 32 bit
    >> processor ? Is there some problem with my compiler ?
    >>
    >> thanks for any help ...
    >>

    > Try the following
    >
    > register long long x;
    >
    > if the compiler claims to be able to store x in a register then I
    > think you'd have legitimate grounds for complaint.


    Um, why?
    --
    "What is appropriate for the master is not appropriate for the novice.
    You must understand the Tao before transcending structure."
    --The Tao of Programming
    Ben Pfaff, Mar 16, 2007
    #9
  10. was Re: data type of size 64 bits on a 32 bit processor

    Malcolm McLean wrote:
    >
    > <> wrote in message

    [... How can "long long" be 64 bits in a 32-bit CPU? ...]
    >
    > Try the following
    >
    > register long long x;
    >
    > if the compiler claims to be able to store x in a register then I think
    > you'd have legitimate grounds for complaint.


    Why? The only thing "register" guarantees is that you can't take
    the address of the object. The following definition "works" just
    fine on my compiler, even with warnings turned to max:

    register char foo[32766];

    Unfortunately, it's not very useful, as strcpy() and printf() can't
    get foo passed as an argument. I get an error "'&' on register
    variable". In fact, even "foo[0] = 'x'" gives that error.

    So, what can one do with a register array?

    --
    +-------------------------+--------------------+-----------------------+
    | Kenneth J. Brody | www.hvcomputer.com | #include |
    | kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
    +-------------------------+--------------------+-----------------------+
    Don't e-mail me at: <mailto:>
    Kenneth Brody, Mar 16, 2007
    #10
  11. "Malcolm McLean" <> writes:
    > <> wrote in message
    >> I am using a gcc compiler for a 32 bit powerpc processor. When I
    >> look at the size of unsigned long long, it displays 8 bytes. I was
    >> wondering, how we can have a data type of 64 bits on a 32 bit
    >> processor ? Is there some problem with my compiler ?
    >>
    >> thanks for any help ...
    >>

    > Try the following
    >
    > register long long x;
    >
    > if the compiler claims to be able to store x in a register then I
    > think you'd have legitimate grounds for complaint.


    If the compiler accepts that declaration without complaint, that
    doesn't mean that the compiler claims to be able to store x in a
    register. The "register" keyword merely "suggests that access to the
    object be as fast as possible" (C99 6.7.1p4). The compiler could
    silently ignore the "register" keyword (except that it must diagnose
    any attempt to compute x's address).

    Even if, for example, long long is 64 bits and CPU registers are 32
    bits, a compiler could plausibly store x in two registers.

    --
    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, Mar 16, 2007
    #11
  12. Ian Collins Guest

    Keith Thompson wrote:
    > "Malcolm McLean" <> writes:
    >
    >><> wrote in message
    >>
    >>> I am using a gcc compiler for a 32 bit powerpc processor. When I
    >>>look at the size of unsigned long long, it displays 8 bytes. I was
    >>>wondering, how we can have a data type of 64 bits on a 32 bit
    >>>processor ? Is there some problem with my compiler ?
    >>>
    >>>thanks for any help ...
    >>>

    >>
    >>Try the following
    >>
    >>register long long x;
    >>
    >>if the compiler claims to be able to store x in a register then I
    >>think you'd have legitimate grounds for complaint.

    >
    >
    > If the compiler accepts that declaration without complaint, that
    > doesn't mean that the compiler claims to be able to store x in a
    > register. The "register" keyword merely "suggests that access to the
    > object be as fast as possible" (C99 6.7.1p4). The compiler could
    > silently ignore the "register" keyword (except that it must diagnose
    > any attempt to compute x's address).
    >
    > Even if, for example, long long is 64 bits and CPU registers are 32
    > bits, a compiler could plausibly store x in two registers.
    >

    Which is what happened on 16 bit x86 processors with 32 bit longs.

    --
    Ian Collins.
    Ian Collins, Mar 16, 2007
    #12
  13. On Mar 16, 2:40 pm, "Malcolm McLean" <> wrote:
    > <> wrote in message
    > > I am using a gcc compiler for a 32 bit powerpc processor. When I
    > > look at the size of unsigned long long, it displays 8 bytes. I was
    > > wondering, how we can have a data type of 64 bits on a 32 bit
    > > processor ? Is there some problem with my compiler ?

    >
    > Try the following
    >
    > register long long x;
    >
    > if the compiler claims to be able to store x in a register then I think
    > you'd have legitimate grounds for complaint.


    Indeed, but how would it go about claiming that? There's no way in C
    for it to do so since C knows nothing about machine registers. All the
    register keyword means in C is that you can't use the address operator
    on an object with register storage class.
    J. J. Farrell, Mar 17, 2007
    #13
  14. Jack Klein Guest

    On 16 Mar 2007 06:35:05 -0700, "ziibrs" <>
    wrote in comp.lang.c:

    >
    > As in C99:
    >
    > long long and its unsigned counterpart unsigned long long are new
    > types in C99. A long long variable shall have at least 64 bits.
    >
    > there is a long double with 96bits that also exists on 32bit machines


    Really? Can you tell me where to find it on an ARM11? How about on a
    Cell processor?

    For that matter, I'd like to see you find one on any x86, 16-bit,
    32-bit, or 64-bit. Keep looking until you find it, we'll wait.

    > in fact the xx-bit architecture does very little to do with variable
    > sizes ( of course it is ment to be that int is as long as the memory
    > address), because when storing variable in registers u can use more
    > than one. I am not a specialist in hardware but as i understand in
    > fact we have one long register that emulates smaller ones. And if wee
    > need we can emuleate a 64-bit or even lager register to store data in.


    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://c-faq.com/
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
    Jack Klein, Mar 17, 2007
    #14
  15. Jack Klein Guest

    On Fri, 16 Mar 2007 21:11:36 +0000, Mark McIntyre
    <> wrote in comp.lang.c:

    > On 16 Mar 2007 05:40:11 -0700, in comp.lang.c ,
    > "" <> wrote:
    >
    > >Hi,
    > >
    > > I am using a gcc compiler for a 32 bit powerpc processor. When I
    > >look at the size of unsigned long long, it displays 8 bytes. I was
    > >wondering, how we can have a data type of 64 bits on a 32 bit
    > >processor ?

    >
    > This isn't a C question.
    >
    > <OT>
    > The width of the bus only restricts the amount of addressable space,
    > not the size an object can be.


    The width of which bus? The size of the address space is not
    necessarily, and quite frequently not actually, related to the data
    bus width.

    Simple example, the Intel 8088 could access 1,048,576 octets of memory
    with an 8-bit data bus. The Intel 8086 could access 1,048,576 octets
    of memory with a 16-bit data bus.

    > For more info, read any history book about computing.
    > </OT>


    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://c-faq.com/
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
    Jack Klein, Mar 17, 2007
    #15
  16. Jack Klein Guest

    On Fri, 16 Mar 2007 14:46:07 -0700, Ben Pfaff <>
    wrote in comp.lang.c:

    > "" <> writes:
    >
    > > I am using a gcc compiler for a 32 bit powerpc processor. When I
    > > look at the size of unsigned long long, it displays 8 bytes. I was
    > > wondering, how we can have a data type of 64 bits on a 32 bit
    > > processor ? Is there some problem with my compiler ?

    >
    > How do you do arithmetic by hand on numbers with more than one
    > digit? The computer can do multi-word arithmetic the same way.


    Often incorrectly. That's why I program computers to do it for me.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://c-faq.com/
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
    Jack Klein, Mar 17, 2007
    #16
  17. user923005 Guest

    On Mar 16, 2:40 pm, "Malcolm McLean" <> wrote:
    > <> wrote in message
    > > I am using a gcc compiler for a 32 bit powerpc processor. When I
    > > look at the size of unsigned long long, it displays 8 bytes. I was
    > > wondering, how we can have a data type of 64 bits on a 32 bit
    > > processor ? Is there some problem with my compiler ?

    >
    > > thanks for any help ...

    >
    > Try the following
    >
    > register long long x;
    >
    > if the compiler claims to be able to store x in a register then I think
    > you'd have legitimate grounds for complaint.


    The register keyword is only a suggestion. The compiler is free to
    ignore it.
    Now, if you take the address of x later on, then the compiler is
    forced to complain about it.

    > --
    > Free games and programming goodies.http://www.personal.leeds.ac.uk/~bgy1mm
    user923005, Mar 17, 2007
    #17
  18. jaysome Guest

    On 16 Mar 2007 06:35:05 -0700, "ziibrs" <>
    wrote:

    >
    >As in C99:
    >
    >long long and its unsigned counterpart unsigned long long are new
    >types in C99. A long long variable shall have at least 64 bits.
    >
    >there is a long double with 96bits that also exists on 32bit machines


    Where did you get that notion?

    Microsoft Visual Studio 6 and Visual Studio 2005 use the same
    representation (8 bytes, 64 bits) for types double and long double,
    even though they could do better with long double and support the
    80-bit extended precision type of the Intel FPU (which gcc supports).
    See

    http://support.microsoft.com/default.aspx?scid=kb;en-us;129209

    for Microsoft's explanation.

    --
    jay
    jaysome, Mar 17, 2007
    #18
  19. In article <>,
    user923005 <> wrote:

    >The register keyword is only a suggestion. The compiler is free to
    >ignore it.
    >Now, if you take the address of x later on, then the compiler is
    >forced to complain about it.


    Nitpick: I don't think that's exactly true (though that is the intent
    of that particular constraint).

    Taking the address of a register-qualified variable is a constraint
    violation, but an implementation that issues a warning on seeing the
    "register" keyword:
    --------
    foo.c: line 42: Warning: Ignoring "register" keyword (I trust my judgement
    on register allocation more than yours)
    --------
    has issued the required diagnostic and is under no obligation to complain
    if its address is later taken.


    dave

    --
    Dave Vandervies
    A lot of hard work by very smart people produced something only a certified
    genius could use in any but the simplest settings. Go look it up; it's
    eye-opening. --Eric Sosman in comp.lang.c
    Dave Vandervies, Mar 18, 2007
    #19
  20. Ben Pfaff Guest

    Re: was Re: data type of size 64 bits on a 32 bit processor

    Kenneth Brody <> writes:

    > The only thing "register" guarantees is that you can't take
    > the address of the object. The following definition "works" just
    > fine on my compiler, even with warnings turned to max:
    >
    > register char foo[32766];


    There are serious pitfalls in trying to use an array with
    register class. See 6.3.2.1p3 (in C99). The last sentence is
    the important part:

    Except when it is the operand of the sizeof operator or the
    unary & operator, or is a string literal used to initialize
    an array, an expression that has type ``array of type'' is
    converted to an expression with type ``pointer to type''
    that points to the initial element of the array object and
    is not an lvalue. If the array object has register storage
    class, the behavior is undefined.

    --
    "Some people *are* arrogant, and others read the FAQ."
    --Chris Dollin
    Ben Pfaff, Mar 18, 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. GGG
    Replies:
    10
    Views:
    12,510
    Donar
    Jul 6, 2006
  2. brahatha
    Replies:
    1
    Views:
    645
  3. Zhi
    Replies:
    2
    Views:
    1,119
    Mike Treseler
    Oct 9, 2007
  4. johnny
    Replies:
    3
    Views:
    2,967
    Tomás Ó hÉilidhe
    Jan 9, 2009
  5. xyz
    Replies:
    2
    Views:
    804
Loading...

Share This Page