From owner-freebsd-current@FreeBSD.ORG Wed Jul 11 02:58:23 2007 Return-Path: X-Original-To: freebsd-current@freebsd.org Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id AA82B16A421 for ; Wed, 11 Jul 2007 02:58:23 +0000 (UTC) (envelope-from ache@nagual.pp.ru) Received: from nagual.pp.ru (nagual.pp.ru [194.87.13.69]) by mx1.freebsd.org (Postfix) with ESMTP id 2A65B13C483 for ; Wed, 11 Jul 2007 02:58:22 +0000 (UTC) (envelope-from ache@nagual.pp.ru) Received: from nagual.pp.ru (ache@localhost [127.0.0.1]) by nagual.pp.ru (8.14.1/8.14.1) with ESMTP id l6B2wLaP035717; Wed, 11 Jul 2007 06:58:21 +0400 (MSD) (envelope-from ache@nagual.pp.ru) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nagual.pp.ru; s=default; t=1184122701; bh=ZtWyXiIDbLl1MkpzfyF/rhnPEfFO9uylxh8AZgY +9gE=; l=1128; h=Received:Date:From:To:Subject:Message-ID: Mail-Followup-To:References:MIME-Version:Content-Type: Content-Disposition:In-Reply-To:User-Agent; b=FGROEYLPe0pqoZuhd4NY NsDFtPuzk+uX3HRplo2la0V9v0ZMM9BjRI74gulXY8qYWGjOyffcSwsUmA9ZjzaSaJj FRTr8B/kAXgU+QTifBD1zui2EUiCzo37ZUvY8nTRJVBwJDESyR7YigoZH6GlhsmgyM2 14Nod53VwUpqnBFw4= Received: (from ache@localhost) by nagual.pp.ru (8.14.1/8.14.1/Submit) id l6B2wLdg035716; Wed, 11 Jul 2007 06:58:21 +0400 (MSD) (envelope-from ache) Date: Wed, 11 Jul 2007 06:58:21 +0400 From: Andrey Chernov To: Peter Jeremy , freebsd-current@freebsd.org Message-ID: <20070711025820.GA35503@nagual.pp.ru> Mail-Followup-To: Andrey Chernov , Peter Jeremy , freebsd-current@freebsd.org References: <20070703182400.Q1449@baba.farley.org> <20070709145418.T52164@thor.farley.org> <20070710154148.GA22873@nagual.pp.ru> <20070710213602.GX3434@turion.vk2pj.dyndns.org> <20070710224619.GA31654@nagual.pp.ru> <20070710225752.GA3000@owl.midgard.homeip.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20070710225752.GA3000@owl.midgard.homeip.net> User-Agent: Mutt/1.5.16 (2007-06-09) Cc: Subject: Re: HEADS UP: getenv() and family API change X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Jul 2007 02:58:23 -0000 On Wed, Jul 11, 2007 at 12:57:52AM +0200, Erik Trulsson wrote: > Not the pointer, but the string it points to can be put into read-only > memory. > > Example: > > static char *s = "PATH=/bin"; > static char *t = "PATH=/bin"; > > > Here both 's', and 't' can point into read-only memory where the string > "PATH=/bin" has been placed. Not only that, they may point to the same > place, i.e. there need only be one copy of the string "PATH=/bin" in > the program (but there may be two distinct copies if the compiler does not > coalesce identical string constants.) > > > If on the other hand you use > > static char s[] = "PATH=/bin"; > static char t[] = "PATH=/bin"; > > > Then 's' and 't' are no longer pointers to a string constant, but arrays > that are initialized with the string "PATH=/bin". These arrays are > modifiable and distinct - i.e. there will be (at least) two copies of the > string "PATH=/bin" in memory. Yes, I agree. Moreover, currently gcc 4.2.0 coalesce "char *" pointed to identical string constants and move them to .rodata, so s[] way is better. -- http://ache.pp.ru/