size of pointers

I

iamgodk

ÓÚ Tue, 19 Dec 2006 09:48:39 +0000£¬Keith Thompsonдµ½£º
iamgodk said:
ÓÚ Tue, 19 Dec 2006 09:21:06 +0000£¬peteдµ½£º [...]
What somebody can learn from me, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
is that the original poster was wrong, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
and that you were wrong to suggest otherwise.
What somebody can learn from you,
is that I must select new suitable cases for answer.
That's right. It's my fault. And then,
please remeber u have not reply to the original poster until now:)
Whoever are you, please give the original poster valuable answer
rather than give me the unilateralism answer for my post:)
Thanks.

Learn to accept criticism.
You are right. Thanks for your advice.
 
I

iamgodk

ÓÚ Tue, 19 Dec 2006 09:50:19 +0000£¬Richard Heathfieldдµ½£º
pete said:




Not to trust iamgodk's advice about the C language. And that's a useful
lesson in itself.

anybody access the web "mindspring.com", and they will discover
"mindspring.com" is related with "earthlink.net".
"see.sig.invalid" may be the same.
 
R

Richard Heathfield

iamgodk said:
? Tue, 19 Dec 2006 09:50:19 +0000?Richard Heathfield???


anybody access the web "mindspring.com", and they will discover
"mindspring.com" is related with "earthlink.net".
"see.sig.invalid" may be the same.

If you think I'm a sock-puppet for pete, think again, and look for
counter-evidence that might disprove your claim. It will be surprisingly
easy to find.
 
C

CBFalconer

jacob said:
subramanian a écrit :


No.

It is true that memory locations are integers, in some
machines a sequence of integers that refer to sequential
memory locations x, x+1, x+2, x+3, etc.

This is also very wrong. An elementary counter example is the
segmented X86 memory.
 
R

Richard Heathfield

jacob navia said:
Richard Heathfield a écrit :
Yes they are

Here's a counter-example:

#include <stdio.h>

int main(void)
{
int i = 42;
void *p = &i;
printf("[%p]\n", p);
return 0;
}

Output:

[DS:0400]

Are you arguing that DS:0400 is an integer?
 
J

jacob navia

Richard Heathfield a écrit :
jacob navia said:

Richard Heathfield a écrit :


Yes they are


Here's a counter-example:

#include <stdio.h>

int main(void)
{
int i = 42;
void *p = &i;
printf("[%p]\n", p);
return 0;
}

Output:

[DS:0400]

Are you arguing that DS:0400 is an integer?

Of course it is an integer, it is the 0400th integer of
the sequence 0... sizeof data segment!!!

Can't you read?

DS:0400 is an integer offset within the
data segment. As I explained in my message, there can
be different memory areas, and pointers can be
of different sizes depending of the memory area.

But you take out a sentence of my message and
put it in another special context just because
you have nothing else to do this morning than
starting again those endless polemic stuff that you
like so much


0400 is a floating point number?

Or you interpret that as a complex number maybe?
 
K

Keith Thompson

jacob navia said:
Richard Heathfield a écrit :
jacob navia said:
Richard Heathfield a écrit :

jacob navia said: [...]
It is true that memory locations are integers,

No, it isn't.

Yes they are
Here's a counter-example:
#include <stdio.h>
int main(void)
{
int i = 42;
void *p = &i;
printf("[%p]\n", p);
return 0;
}
Output:
[DS:0400]
Are you arguing that DS:0400 is an integer?

Of course it is an integer, it is the 0400th integer of
the sequence 0... sizeof data segment!!!

Can't you read?

0400 is an integer.

DS:0400 is not an integer.

Integers are not pointers. Pointers are not integers. This is
fundamental to an understanding of C.
DS:0400 is an integer offset within the
data segment. As I explained in my message, there can
be different memory areas, and pointers can be
of different sizes depending of the memory area.

Not in standard C; see my other followup.
 
R

Random832

2006-12-19 said:
What's the point of saying:
machine word is 32bit
sizeof(int) == 4
sizeof(char *) == 4
sizeof(int *) == 4
?

What is anybody supposed to be able to learn from that?

That you can do certain things on a VAX that you might not be able to do
on some other architectures where these assumptions don't hold?
 
R

Random832

2006-12-19 said:
Richard Heathfield a écrit :
jacob navia said:

Richard Heathfield a écrit :

jacob navia said:



subramanian a écrit :


I have been thinking that all pointers(to any obejct) have the same
size. The size of a pointer is the size of an int. This is beause a
memory location is addressed by an int. Is that right/wrong?


No.

It is true that memory locations are integers,


No, it isn't.


Yes they are


Here's a counter-example:

#include <stdio.h>

int main(void)
{
int i = 42;
void *p = &i;
printf("[%p]\n", p);
return 0;
}

Output:

[DS:0400]

Are you arguing that DS:0400 is an integer?

Of course it is an integer, it is the 0400th integer of
the sequence 0... sizeof data segment!!!

Can't you read?

DS:0400 is an integer offset within the
data segment. As I explained in my message, there can
be different memory areas, and pointers can be
of different sizes depending of the memory area.

But you take out a sentence of my message and
put it in another special context just because
you have nothing else to do this morning than
starting again those endless polemic stuff that you
like so much


0400 is a floating point number?

Or you interpret that as a complex number maybe?

He meant the whole of "DS:0400" is not an integer.

For an example you might be less able to explain away... in what way is
"(SPP:0000 :1aefRMA_INTPTRMJK 070591 :10320:4:28)" an integer? Now, it
does contain integers, but it's not at all obvious how they're related
to offsets within physical memory, or to fields within the 16-byte
pointer object.
 
K

Kenneth Brody

subramanian said:
I have been thinking that all pointers(to any obejct) have the same
size. The size of a pointer is the size of an int. This is beause a
memory location is addressed by an int. Is that right/wrong?

As pointed out elsethread, this is wrong on all counts.

Consider the 16-bit segmented world of "real mode" x86 programming.
In such an environment, you may have:

sizeof(int) == 2
sizeof(char near *) == 2
sizeof(char far *) == 4
sizeof(char *) == either 2 or 4, depending on compiler options

(Note, "near" and "far" are not standard. However, you are likely
to come across such extensions in the 16-bit x86 world.)

Also, in the world of 32-bit "protected mode" x86 programming, you
might have:

sizeof(int) == 4
sizeof(char *) == 4
sizeof(char far *) == 6

I have no idea what you might get in the 64-bit x86 world, but I
would suspect that there are 8-byte integer types as well as 8-byte
pointer types, in addition to 4-byte integer and pointer types.

Finally, there are CPUs in which integers and pointers are stored
in different registers while being used by the CPU. (For example,
the 68000 line of CPUs has a set of "D" registers for data, and a
separate set of "A" registers for addresses/pointers.)

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:[email protected]>
 
R

Richard Bos

iamgodk said:
ÓÚ Tue, 19 Dec 2006 09:21:06 +0000£¬peteдµ½£º

What somebody can learn from you,
is that I must select new suitable cases for answer.

No. What they can learn - and what _you_ _should_ learn - is that no
single specific case is an answer to the OP's question. Any single case
constitutes misinformation. The answer to the OP's question is simple:
no, the sizes of ints and of the various kinds of object pointers are
_not_ necessarily the same, because pointers are _not_ integers.
Whoever are you, please give the original poster valuable answer

This has already been done.
rather than give me the unilateralism

That word does not mean what you think it does.

Richard
 
R

Richard Bos

jacob navia said:
Richard Bos a écrit :

Yes, you should take that to heart

I'm not the one pretending that all computers work like the only ones
I've had experience with, you know. You are.

Richard
 
M

Malcolm

Richard Bos said:
Entirely wrong, on all three counts.
Almost right. But actually, as you say, wrong.

Most computers have a flat memory and no funny things like 8 bit chars
implemented on top of 32-bit machine bytes. So all pointers are of the same
size. However you get a few wierdos - the one I mentioned is a case in
point. On one of Chris Torek's machines char *s are tagged with an extra two
bits, so are slightly bigger than other pointers. void *s, are, of course,
also bigger.

Most computer s amke no distinction between address registers, which in C
terms hold pointers, and integer pointers. Until 64 bit machines came along,
int was always the natural register size, so pointers and int were generally
the same size. Even now, some foolish people refuse to join my campaign for
64 bit ints, and we migh see 64-bit pointers and 32 bit ints becoming
common.

Interconvertibility between pointers and ints is not, however, an advantage
of 64 bit ints, as far as I can identify.

Addresses are usually integers - bytes are whole things - but the OP would
have to classify what he means by "addressed by an int". As Richard
Heathfield pointed out, the memory might also be segmented.
 
S

Stephen Sprunk

Malcolm said:
Almost right. But actually, as you say, wrong.

Most computers have a flat memory and no funny things like ...

Most is not good enough. What you're saying is that your statement is
true on any systems for which it is true -- circular logic. In reality,
a statement is false if there is a single counter-example, and there are
plenty of counter-examples to yours.

Now, _you_ may not care about any of the hundreds of platforms C runs on
besides your i386 Linux/Win32 box, but if you write code with those
flawed assumptions that's all your code will be guaranteed to run on.
If you want _portable_ code, you accept that all the world is not a
VAX^H^H^Hi386 and write your code accordingly.

Trying to push your closed-minded views about what platforms matter is
not going to go over well in a forum filled with people who make their
living writing code for platforms you have deemed irrelevant.

S
 
K

Keith Thompson

Malcolm said:
Almost right. But actually, as you say, wrong.

Most computers have a flat memory and no funny things like 8 bit chars
implemented on top of 32-bit machine bytes. So all pointers are of the same
size.

So you have a choice. You can think in terms of a memory model
("pointers are integers") that happens to be valid for *most*
machines. Or you can think in terms of a more general memory model
("pointers are pointers; integers are integers") that is valid for
*all* machines.

Since this newsgroup discusses a programming language, not some
limited (though large) subset of existing hardware, I choose the
latter. In the context of general C programming, the assumption that
pointers are integers is not only untrue; it's not particularly
helpful in understanding what's going on.
 
R

Richard Heathfield

onkar said:
Thas wrong

You're correct to claim that he's wrong...
- Pointers are of the type "unsigned integers".

....but incorrect to make this claim that pointers have unsigned integer
type. In fact, they have pointer type. See 3.1.2.5 Types (or 6.2.5 Types in
C99).
 

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,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top