A
anish kumar
size of void * is not always equal to size of int * ?
If it is not then what is the reasoning?
If it is not then what is the reasoning?
size of void * is not always equal to size of int * ?
Correct.
If it is not then what is the reasoning?
James Kuyper said:There's no requirement that they be equal, and that is, for me,
sufficient reason not write code that makes the assumption that they are
equal.
However, it's also the case that there are some real world systems where
there's a good reason for them being different. Every real world case
that I'm familiar with involves hardware where the size of an
addressable storage unit is too large to be convenient for use as a C
byte. CHAR_BITS is choose so that N*CHAR_BITS is the number of bits in a
addressable storage unit. Then if _Alignof(T*) >= N, T* need only
contain the machine address of the storage unit containing the start of
the object. However, if _Alignof(T*) < N, then a T* must contain not
only the machine address, but also the byte offset within the storage
unit identified by that address. The extra space required to store that
extra information make result in int(void*) (which must have the same
representation as 'char*', and must therefore be able to point at
individual bytes within a storage unit) being larger than sizeof(int*).
(I hate to be picky, but ... ok, actually I don't hate to be picky.)
It's also worth noting that it's sometimes possible to store those extra
offset bits within the pointer itself, if there are some extra bits
available for the purpose.
To fake up 8-bit bytes on system which only allow 32-bit addressing.size of void * is not always equal to size of int * ?
If it is not then what is the reasoning?
size of void * is not always equal to size of int * ?
If it is not then what is the reasoning?
On 05/02/2014 03:37 PM, Keith Thompson wrote:
....
I don't mind being corrected - but I do wish I hadn't needed correction. :-(
That's the key reason why I said only that the extra information *might*
require a larger size.
Ken Brody said:(snip)
I worked on hardware where the address was 18 bits wide, but a "pointer"
could require 36 bits. The data "word" was 36 bits wide, and there were
hardware instructions to do things such as "pull the next 7 bits of data
from this pointer, put it in this register, and increment the pointer by 7
bits", where extra data beyond just the address was kept in the other 18
bits. (Strings, for example, were typically stored with five 7-bit ASCII
characters per word, with one bit wasted.)
I never programmed in C on this hardware, but my guess would be
that all pointers would be 36 bits, simply because it would
require less overhead as compared to packing data into memory.
However, I see no reason why such an implementation couldn't
exist where the address bus was as wide as the data bus,
thereby requiring "void*" to be wider than what would be
necessary, for example, for an "int*".
I worked on hardware where the address was 18 bits wide, but a
"pointer" could require 36 bits. The data "word" was 36 bits wide, and
there were hardware instructions to do things such as "pull the next 7
bits of data from this pointer, put it in this register, and increment
the pointer by 7 bits", where extra data beyond just the address was
kept in the other 18 bits. (Strings, for example, were typically
stored with five 7-bit ASCII characters per word, with one bit
wasted.) [...]
I never programmed in C on this hardware, but my guess would be that
all pointers would be 36 bits, simply because it would require less
overhead as compared to packing data into memory.
The DEC PDP-10 uses 18 bit addresses in 36 bit words, but later systems
extended the address space (I don't know the details well, though). The
PDP-10 also has byte pointers that can address bytes of from 1 to 36
bits, and index through strings of them. In addition to byte pointers,
the PDP-10 has instructions for operations of the upper or lower half of
36 bit words.
As well as I know it, for many core memory machines it cost about $1 per
8 bits for memory. No-one would have imagined a use for 36 bit address
buses. For the PDP-10, the address is per task, such that each program
has its own address space. (The physical address might be bigger.)
When I was in college, the computer department was tossing out
their ancient computer magazine collection. I, being a geek,
looked through them, and remember an ad for memory at a
breakthrough cost of "less than 50 cents a bit".
When I was in college, the computer department was tossing out their ancient
computer magazine collection. I, being a geek, looked through them, and
remember an ad for memory at a breakthrough cost of "less than 50 cents a bit".
Cool, so, way back then, they had 32 bit bytes. =)
Lynn McGuire said:Nope, six bit bytes (no lowercase). 36 bit
words, 60 bit words and then 32 bit words when
the eight bit bytes got popular.
I think he means bits in the sense of one eighth of a dollar.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.