Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 17 Aug 2005 16:51:29 -0500
From:      "Joshua Weaver" <josh@metropark.com>
To:        "'Erik Trulsson'" <ertr1013@student.uu.se>, "'Sergey Matveychuk'" <sem@freebsd.org>
Cc:        questions@freebsd.org
Subject:   RE: man malloc
Message-ID:  <200508172151.j7HLpNTv028906@web.metropark.com>
In-Reply-To: <20050817213243.GA26065@falcon.midgard.homeip.net>

next in thread | previous in thread | raw e-mail | index | archive | help
Pointer coercion is standard terminology, it is used when you force cast a
pointer as a different data type.
Btw, most processors since the late 90's can handle a variable not aligned
to their word length, so it would be uncommon.

Good question, Sergey.

Josh

> -----Original Message-----
> From: owner-freebsd-questions@freebsd.org [mailto:owner-freebsd-
> questions@freebsd.org] On Behalf Of Erik Trulsson
> Sent: Wednesday, August 17, 2005 4:33 PM
> To: Sergey Matveychuk
> Cc: questions@freebsd.org
> Subject: Re: man malloc
> 
> On Thu, Aug 18, 2005 at 01:03:46AM +0400, Sergey Matveychuk wrote:
> > I know it may be stupid, but I can't understand this sentence from
> > malloc(3) man page:
> >
> > "
> > The allocated space is suitably aligned (after possible pointer
> > coercion) for storage of any type of object.
> > "
> >
> > What does "suitable aligned for storage of *any* type of object" means?
> 
> In what way is that difficult to understand?  It can't really be expressed
any
> simpler, and it means exactly what it says:  That the storage allocated by
malloc is
> suitably aligned for storing any kind of object.
> 
> As an example, it is not uncommon for many systems to require that a
> 32-bit integer must be aligned on a 4-byte boundary. (I.e. if the CPU
tries
> to access such an object placed on an address that is not a multiple of 4,
> then the program will crash.)  Exactly what alignment is required for
> different objects can vary quite a bit, but malloc guarantees that the
> storage it allocates is aligned in such a way that you can store any kind
> object in it (assuming it is large enough, of course.)
> 
> 
> 
> > What is pointer coercion?
> 
> No idea.  It is not standard terminology anway.
> 
> > I have no pointer before malloc() returns.
> 
> Then where do you store the value returned by malloc?
> You almost certainly do have some pointer even before malloc returns, but
> that pointer might not contain any useful value.
> 
> 
> --
> <Insert your favourite quote here.>
> Erik Trulsson
> ertr1013@student.uu.se
> _______________________________________________
> freebsd-questions@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to
"freebsd-questions-unsubscribe@freebsd.org"




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200508172151.j7HLpNTv028906>