Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 31 Mar 2001 05:42:12 -0800
From:      Matthew Hunt <mph@astro.caltech.edu>
To:        Vladimir Mandro <vlaman@smela.ldc.net>
Cc:        freebsd-bugs@FreeBSD.ORG
Subject:   Re: bug in gcc or my hands?
Message-ID:  <20010331054212.A5816@wopr.caltech.edu>
In-Reply-To: <E14jLOP-0000yy-00@vlaman.smela.ldc.net>; from vlaman@smela.ldc.net on Sat, Mar 31, 2001 at 04:26:13PM %2B0300
References:  <E14jLOP-0000yy-00@vlaman.smela.ldc.net>

next in thread | previous in thread | raw e-mail | index | archive | help
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 <mph@astro.caltech.edu> * 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




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