different struct sizes

  • Thread starter Borked Pseudo Mailed
  • Start date
K

Keith Thompson

Ben Pfaff said:
Every byte of memory represents a number. Because a pointer is
made out of bytes, it can also be said to be represented by a
number, formed by concatenating bits. For many implementation,
this number is meaningful.

Ok, but it's not *necessarily* meaningful, and any meaning it might
have isn't what I meant when I referred to even and odd byte
addresses.
 
R

Richard Bos

Ben Pfaff said:
We may be talking past one another. I agree that the result of
subtracting pointers must be 1 in this case. But the numbers
that represent the pointers involved in the subtraction could
differ by 2, or by 4, or by 623.

Those numbers can then only reside at a level that is completely
inaccessible to the ISO C program.
I don't think the concepts of even and odd addresses would be
meaningful in the architecture that I'm envisioning.
Potentially, all pointers could be represented by odd numbers, or
by even numbers, or the bit with value 1 could be the parity of
the rest of the bits, or whatever.

Potentially, all objects could be represented by postits stuck to the
legs of carrier pigeons, and pointers by the name of the pigeon to which
the relevant postit is stuck. But to a C program, the difference between
one byte address and the next is still 1, and not "The bit of chicken
wire between Clara and Pete".

Richard
 
R

Richard Bos

Jordan Abel said:
How is strings system-level?

It's a program which one finds supplied by one's OS, and one may expect
people who write OS utility programs not to be fazed by oddities in
character sets or unusual integer sizes.

Richard
 
B

Ben Pfaff

Those numbers can then only reside at a level that is completely
inaccessible to the ISO C program.

That is not true. ISO C programs are able to access the bytes
that comprise a pointer value.
 
J

Jordan Abel

2006-11-09 said:
That is not true. ISO C programs are able to access the bytes
that comprise a pointer value.

Yes, but they can't tell what number or numbers said bytes represent.
 
B

Ben Pfaff

Jordan Abel said:
Yes, but they can't tell what number or numbers said bytes represent.

It's only relevant to talk about odd or even addresses, in my
opinion, if they do have some meaning.
 
M

Mark McIntyre

Keith said:
A C implementation *must* allow char objects to be stored at odd byte
addresses. It can choose to align all single declared char objects,
or even char struct members, at even addresses if that makes access
easier or faster, but there can be no padding between array elements:

char arr[2];
/* either arr[0] or arr[1] is at an odd byte address */

If the hardware doesn't allow this (or makes it too expensive), then
the implementation can make bytes bigger than 8 bits.

How do you define "odd byte address" ?

I don't see why you can't have 16-bit bytes, at addresses 0, 2, 4, ...

the point is, a byte is defined in C as the smallest uniquely
addressable object. Whether you choose to number adjacent objects
0,1,2... or 0,2,4 or pi, e, tau,.. is entirely up to you, but the
spacing between them is still unity....

--
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
 

Ask a Question

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.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top