From owner-freebsd-questions@FreeBSD.ORG Fri Aug 19 10:52:39 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 72CA416A41F for ; Fri, 19 Aug 2005 10:52:39 +0000 (GMT) (envelope-from keramida@ceid.upatras.gr) Received: from aiolos.otenet.gr (aiolos.otenet.gr [195.170.0.93]) by mx1.FreeBSD.org (Postfix) with ESMTP id AB72A43D46 for ; Fri, 19 Aug 2005 10:52:38 +0000 (GMT) (envelope-from keramida@ceid.upatras.gr) Received: from flame.pc (aris.bedc.ondsl.gr [62.103.39.226]) by aiolos.otenet.gr (8.13.4/8.13.4/Debian-1) with SMTP id j7JAqan4017109; Fri, 19 Aug 2005 13:52:37 +0300 Received: from flame.pc (flame [127.0.0.1]) by flame.pc (8.13.4/8.13.4) with ESMTP id j7JAqYON001661; Fri, 19 Aug 2005 13:52:34 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Received: (from keramida@localhost) by flame.pc (8.13.4/8.13.4/Submit) id j7ILe3Av000718; Fri, 19 Aug 2005 00:40:03 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Date: Fri, 19 Aug 2005 00:40:03 +0300 From: Giorgos Keramidas To: Dmitry Mityugov Message-ID: <20050818214003.GA687@flame.pc> References: <4303A632.1000809@FreeBSD.org> <4303B016.3030201@mac.com> <43044212.20909@FreeBSD.org> <20050818125348.GG1282@flame.pc> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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: Fri, 19 Aug 2005 10:52:39 -0000 On 2005-08-18 22:17, Dmitry Mityugov wrote: >On 8/18/05, Giorgos Keramidas wrote: >>On 2005-08-18 12:08, Sergey Matveychuk wrote: >>>Chuck Swiger wrote: >>>>>What is pointer coercion? I have no pointer before malloc() returns. >>>> >>>> Right. Well, malloc returns a (void *), but most people want to use the >>>> memory malloc returns to hold their own arrays, structs, whatever, which >>>> means that you need to be able to coerce the (void *) malloc gave you >>>> into whatever pointer type you want to actually use. >>>> >>>> So the memory malloc gives you needs to be aligned so that it's OK to be >>>> used for even the most restrictive datatype known to the system, >>>> commonly 8, 16, or 32 bytes. >>> >>> Pointer coercion means a type cast? I see now. >>> I read it as 'force change of pointer value' before. >> >> It may be surprising, but casting back and forth *MAY* change the value >> of the pointer. >... > > Could you back up this assertion with an example, please? Do I really have to? The standard says that casting is only allowed from (type *) to (void *) and back to (type *). This is exactly the reason why malloc() knows (using its own "magic") what to return, so that you _can_ cast its result.