From owner-freebsd-questions@FreeBSD.ORG Wed Aug 17 21:32:47 2005 Return-Path: X-Original-To: questions@FreeBSD.org Delivered-To: freebsd-questions@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A5DEE16A41F for ; Wed, 17 Aug 2005 21:32:47 +0000 (GMT) (envelope-from ertr1013@student.uu.se) Received: from pne-smtpout1-sn1.fre.skanova.net (pne-smtpout1-sn1.fre.skanova.net [81.228.11.98]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0F78F43D46 for ; Wed, 17 Aug 2005 21:32:46 +0000 (GMT) (envelope-from ertr1013@student.uu.se) Received: from falcon.midgard.homeip.net (212.181.162.201) by pne-smtpout1-sn1.fre.skanova.net (7.2.060.1) id 42B813B0008E61E0 for questions@FreeBSD.org; Wed, 17 Aug 2005 23:32:45 +0200 Received: (qmail 26123 invoked by uid 1001); 17 Aug 2005 23:32:44 +0200 Date: Wed, 17 Aug 2005 23:32:44 +0200 From: Erik Trulsson To: Sergey Matveychuk Message-ID: <20050817213243.GA26065@falcon.midgard.homeip.net> Mail-Followup-To: Sergey Matveychuk , questions@FreeBSD.org References: <4303A632.1000809@FreeBSD.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4303A632.1000809@FreeBSD.org> User-Agent: Mutt/1.5.9i Cc: questions@FreeBSD.org Subject: Re: man malloc X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Aug 2005 21:32:47 -0000 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. -- Erik Trulsson ertr1013@student.uu.se