By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,421 Members | 1,128 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,421 IT Pros & Developers. It's quick & easy.

data type of size 64 bits on a 32 bit processor

P: n/a
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 '07 #1
Share this Question
Share on Google+
24 Replies


P: n/a
ju**********@yahoo.co.in 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?
Mar 16 '07 #2

P: n/a

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.

Mar 16 '07 #3

P: n/a
ju**********@yahoo.co.in 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/

Mar 16 '07 #4

P: n/a
"ju**********@yahoo.co.in" 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:Th*************@gmail.com>

Mar 16 '07 #5

P: n/a
On 16 Mar 2007 05:40:11 -0700, in comp.lang.c ,
"ju**********@yahoo.co.in" <ju**********@yahoo.co.inwrote:
>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
Mar 16 '07 #6

P: n/a

<ju**********@yahoo.co.inwrote 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
Mar 16 '07 #7

P: n/a
"ju**********@yahoo.co.in" <ju**********@yahoo.co.inwrites:
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
Mar 16 '07 #8

P: n/a
"Malcolm McLean" <re*******@btinternet.comwrites:
<ju**********@yahoo.co.inwrote 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
Mar 16 '07 #9

P: n/a
"Malcolm McLean" <re*******@btinternet.comwrites:
<ju**********@yahoo.co.inwrote 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) ks***@mib.org <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"
Mar 16 '07 #10

P: n/a
Keith Thompson wrote:
"Malcolm McLean" <re*******@btinternet.comwrites:
>><ju**********@yahoo.co.inwrote 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.
Mar 16 '07 #11

P: n/a
On Mar 16, 2:40 pm, "Malcolm McLean" <regniz...@btinternet.comwrote:
<junky_fel...@yahoo.co.inwrote 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.

Mar 17 '07 #12

P: n/a
On 16 Mar 2007 06:35:05 -0700, "ziibrs" <Ru**************@gmail.com>
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/~a...FAQ-acllc.html
Mar 17 '07 #13

P: n/a
On Fri, 16 Mar 2007 21:11:36 +0000, Mark McIntyre
<ma**********@spamcop.netwrote in comp.lang.c:
On 16 Mar 2007 05:40:11 -0700, in comp.lang.c ,
"ju**********@yahoo.co.in" <ju**********@yahoo.co.inwrote:
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/~a...FAQ-acllc.html
Mar 17 '07 #14

P: n/a
On Fri, 16 Mar 2007 14:46:07 -0700, Ben Pfaff <bl*@cs.stanford.edu>
wrote in comp.lang.c:
"ju**********@yahoo.co.in" <ju**********@yahoo.co.inwrites:
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/~a...FAQ-acllc.html
Mar 17 '07 #15

P: n/a
On Mar 16, 2:40 pm, "Malcolm McLean" <regniz...@btinternet.comwrote:
<junky_fel...@yahoo.co.inwrote 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

Mar 17 '07 #16

P: n/a
On 16 Mar 2007 06:35:05 -0700, "ziibrs" <Ru**************@gmail.com>
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...b;en-us;129209

for Microsoft's explanation.

--
jay
Mar 17 '07 #17

P: n/a
In article <11*********************@e1g2000hsg.googlegroups.c om>,
user923005 <dc*****@connx.comwrote:
>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 dj******@csclub.uwaterloo.ca
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
Mar 18 '07 #18

P: n/a
Malcolm McLean wrote:
>
<ju**********@yahoo.co.inwrote 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:Th*************@gmail.com>

Mar 18 '07 #19

P: n/a
Kenneth Brody <ke******@spamcop.netwrites:
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
Mar 18 '07 #20

P: n/a
Ben Pfaff wrote:
>
Kenneth Brody <ke******@spamcop.netwrites:
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.
Well, I would never use such a thing in real life. I was just
trying to come up with a quick register example which would
obviously not fit in a register in most current systems. (Perhaps
the DS-9000 has such huge registers?)

In any case, I was momentarily suprised to see the compiler
complain about my trying to use the array it allowed me to
create, and was wondering what, if anything, could be done with
such a construct.

What about register struct? Is that UB as well? (Again, this is
just curiosity.)

Then there's the question "why not simply forbid register arrays
in the first place if their use is UB (or put the UB notice in
the register storage class description)?"

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>

Mar 19 '07 #21

P: n/a
Kenneth Brody <ke******@spamcop.netwrites:
[...]
What about register struct? Is that UB as well? (Again, this is
just curiosity.)
I don't see any problem with register struct. Member access isn't
defined in terms of pointers. And if a structure is sufficiently
small (say, a 32-bit structure containing bit fields), then putting it
in a register could make as much sense as putting anything else in a
register. (Not that "register" necessarily implies putting it in a
register.)
Then there's the question "why not simply forbid register arrays
in the first place if their use is UB (or put the UB notice in
the register storage class description)?"
Good question. There might have been some concern about breaking
existing code and/or implementations, but I still would think it would
have made sense to forbid register arrays.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <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"
Mar 19 '07 #22

P: n/a
Keith Thompson wrote:
Kenneth Brody <ke******@spamcop.netwrites:
>>Then there's the question "why not simply forbid register arrays
in the first place if their use is UB (or put the UB notice in
the register storage class description)?"


Good question. There might have been some concern about breaking
existing code and/or implementations, but I still would think it would
have made sense to forbid register arrays.
The risk can always be mitigated through compiler options.

--
Ian Collins.
Mar 19 '07 #23

P: n/a
[Sub-thread started because someone said that "register" on something
too large to fit in a register should be flagged as an error.]

Keith Thompson wrote:
>
Kenneth Brody <ke******@spamcop.netwrites:
[...]
[... "register arrays" invoke UB ...]
What about register struct? Is that UB as well? (Again, this is
just curiosity.)

I don't see any problem with register struct. Member access isn't
defined in terms of pointers. And if a structure is sufficiently
small (say, a 32-bit structure containing bit fields), then putting it
in a register could make as much sense as putting anything else in a
register. (Not that "register" necessarily implies putting it in a
register.)
Hmm...

================
#include <stdio.h>

struct bigstruct
{
char array[32766];
};

int main(void)
{
register struct bigstruct foo = { "foobar" } ;

printf("%ld\n",(long)sizeof(foo));
printf("%p\n",foo.array);
printf("%s\n",foo.array);
}
================

This "runs just fine" here, giving:

32767
00127F80
foobar

Of course, "runs just fine" is allowed for UB as well.

The strange thing here is that foo.array is addressable. I suppose
this is okay, since register arrays invoke UB. Do arrays within
register structs invoke UB?

(Note that "&foo.array" is accepted by the compiler, but "&foo"
is forbidden by the compiler as "'&' on register variable", as
is expected.)

Or is this just getting a bit too esoteric?

The writers of the Standard obviously felt it necessary to state
explicitly that register arrays invoke UB, but they appear to have
missed register structs.

[...]

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>

Mar 20 '07 #24

P: n/a
Kenneth Brody <ke******@spamcop.netwrites:
[Sub-thread started because someone said that "register" on something
too large to fit in a register should be flagged as an error.]

Keith Thompson wrote:
>>
Kenneth Brody <ke******@spamcop.netwrites:
[...]
[... "register arrays" invoke UB ...]
What about register struct? Is that UB as well? (Again, this is
just curiosity.)

I don't see any problem with register struct. Member access isn't
defined in terms of pointers. And if a structure is sufficiently
small (say, a 32-bit structure containing bit fields), then putting it
in a register could make as much sense as putting anything else in a
register. (Not that "register" necessarily implies putting it in a
register.)

Hmm...

================
#include <stdio.h>

struct bigstruct
{
char array[32766];
};

int main(void)
{
register struct bigstruct foo = { "foobar" } ;

printf("%ld\n",(long)sizeof(foo));
printf("%p\n",foo.array);
printf("%s\n",foo.array);
}
================

This "runs just fine" here, giving:

32767
00127F80
foobar
It "runs fine" for me too, but I get a warning

c.c:13: warning: address of register variable `foo' requested

on the line
printf("%p\n",foo.array);

[...]
The writers of the Standard obviously felt it necessary to state
explicitly that register arrays invoke UB, but they appear to have
missed register structs.
Register structs that contain arrays are certainly problematic.
Register structs that *don't* contain arrays are, as far as I can
tell, just fine.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <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"
Mar 20 '07 #25

This discussion thread is closed

Replies have been disabled for this discussion.