From owner-freebsd-bugs Sat Mar 31 5:42:30 2001 Delivered-To: freebsd-bugs@freebsd.org Received: from wopr.caltech.edu (wopr.caltech.edu [131.215.102.114]) by hub.freebsd.org (Postfix) with ESMTP id 1E35937B722 for ; Sat, 31 Mar 2001 05:42:27 -0800 (PST) (envelope-from mph@wopr.caltech.edu) Received: (from mph@localhost) by wopr.caltech.edu (8.11.1/8.11.0) id f2VDgCk05851; Sat, 31 Mar 2001 05:42:12 -0800 (PST) (envelope-from mph) Date: Sat, 31 Mar 2001 05:42:12 -0800 From: Matthew Hunt To: Vladimir Mandro Cc: freebsd-bugs@FreeBSD.ORG Subject: Re: bug in gcc or my hands? Message-ID: <20010331054212.A5816@wopr.caltech.edu> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: ; from vlaman@smela.ldc.net on Sat, Mar 31, 2001 at 04:26:13PM +0300 Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org On Sat, Mar 31, 2001 at 04:26:13PM +0300, Vladimir Mandro wrote: > ---begin of main.c--- > void main() > { > char *s = "Hello"; > *s=0; > } > ---end of main.c--- [...] > Replacing char *s = "Hello" with char s[] = "Hello". All works fine. Literal strings are stored in memory marked read-only; you cannot modify them. The difference is that char s[] = "Hello" places a copy of "Hello" on the stack where it can be modified. > Book "The C Programming Language" by Kernighan&Ritchie tells, that > declaration char *s and char s[] are equivalent. It's wrong or outdated (first edition?), or you are misunderstanding the context in which it says they are equivalent. -- Matthew Hunt * Inertia is a property http://www.pobox.com/~mph/ * of matter. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message