Re: sizeof(ptr) = ?
- From: Richard <rgrdev@xxxxxxxxx>
- Date: Tue, 23 Oct 2007 16:06:57 +0200
"James Kuyper Jr." <jameskuyper@xxxxxxxxxxx> writes:
Richard wrote:
...
We were talking about pointers being different sizes because they are
used to point to different areas in memory. Or I was.
Well, everyone else was talking about pointer that might be different
sizes because they are used to point to objects of different types,
which is a very different thing. However, looking back on the thread,
I see that this was never explicitly stated; people who knew what they
were talking about just assumed that you did too. The key message was:
On 2007-10-22, Richard wrote:
Barry Schwarz <schwarz45@xxxxxxxxx> writes:...
On Oct 22, 2:01 am, "MisterE" <Mist...@xxxxxxxxx> wrote:
addressPointers of any type will have the same size because they hold the
type ofvalue of memory that they point to, thus they always hold the same
depends ondata. On standard PC's this is a 32bit address (4 bytes), but it
the system what the size is.While this may be true in your experience, the C standard imposes no
such restriction. Furthermore, there are systems for which it is not
true.
Could you explain how malloc works for such systems please.
If you knew what Barry Schwarz was talking about, this makes perfect
sense, and seems like a complete answer. However, I can see how it
could be misconstrued the way that you did, which means it wasn't a
complete answer.
I am going back, again, to the pointers being different sizes.
If we agree that all memory from Malloc is to a single "type of
memory". It returns a pointer to "thingies". Lets say this "pointer"
must fit in a void * (which it must).
thingies *p = malloc(2048);// (for example)
at what point can p become bigger or smaller than p2 here:
char *p2=malloc(2048);
Would you agree it can not become smaller since that would imply losing
some address information required for the subsequent call to free()?
If it became bigger than the char * above, I guess the cast to put it
(implicit or explicit) into a void * for a call to free then takes care
of converting it again to something that free understands? But if free
then understands it - what information from its "bigger implementation"
has been lost and how does that get "replaced" when we convert the void
* back to a pointer to thingies?
Maybe I have a head tumor on this thing, but I'm constantly puzzled by
how frequently people tell us that pointers to blocks of memory returned
by malloc can be different sizes.
.
- Follow-Ups:
- Re: sizeof(ptr) = ?
- From: Philip Potter
- Re: sizeof(ptr) = ?
- From: jameskuyper
- Re: sizeof(ptr) = ?
- From: Martin Golding
- Re: sizeof(ptr) = ?
- References:
- sizeof(ptr) = ?
- From: William Xu
- Re: sizeof(ptr) = ?
- From: MisterE
- Re: sizeof(ptr) = ?
- From: Barry Schwarz
- Re: sizeof(ptr) = ?
- From: Richard
- Re: sizeof(ptr) = ?
- From: santosh
- Re: sizeof(ptr) = ?
- From: Richard
- Re: sizeof(ptr) = ?
- From: santosh
- Re: sizeof(ptr) = ?
- From: Richard
- Re: sizeof(ptr) = ?
- From: wisdo
- Re: sizeof(ptr) = ?
- From: Richard
- Re: sizeof(ptr) = ?
- From: santosh
- Re: sizeof(ptr) = ?
- From: Richard
- Re: sizeof(ptr) = ?
- From: James Kuyper Jr.
- sizeof(ptr) = ?
- Prev by Date: Re: Print a short instead of an int... ? What's up with "%hd"?
- Next by Date: Re: Why connot declare a static member of STRUCT or UNION?
- Previous by thread: Re: sizeof(ptr) = ?
- Next by thread: Re: sizeof(ptr) = ?
- Index(es):
Relevant Pages
|