linux-gcc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan-Benedict Glaw <jbglaw@lug-owl.de>
To: linux-gcc@vger.kernel.org
Subject: Re: Are string literals _always_ allocated in the RO section?
Date: Mon, 17 Jan 2005 18:18:53 +0100	[thread overview]
Message-ID: <20050117171853.GG28037@lug-owl.de> (raw)
In-Reply-To: <m3brbq1dtv.fsf@uniton.integrable-solutions.net>

[-- Attachment #1: Type: text/plain, Size: 1156 bytes --]

On Sun, 2005-01-16 00:18:20 +0100, Gabriel Dos Reis <gdr@integrable-solutions.net>
wrote in message <m3brbq1dtv.fsf@uniton.integrable-solutions.net>:
> Denis Zaitsev <zzz@anda.ru> writes:
> 
> | This program:
> | 
> | void x(char *s)
> | {
> |     *s= 'x';
> | }
> | 
> | main()
> | {
> |     x("y");
> | }

> | not <const char*> does nothing in this case.  Should it be considered
> | as a bug?
> 
> In the program? Yes.

Maybe you'd tell him more about the magic :)

char *mytext = "hello";

results in a pointer (which you may later on make pointing to a
different location) that points to a static, read-only string containing
"hello\0". However, if you need to change the text, you need to do it
like this:

char mytext[] = "hello";

Cf. section 6.4.5.6 of the C99 standard.

MfG, JBG

-- 
Jan-Benedict Glaw       jbglaw@lug-owl.de    . +49-172-7608481             _ O _
"Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur | Gegen Krieg  _ _ O
 fuer einen Freien Staat voll Freier Bürger" | im Internet! |   im Irak!   O O O
ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

      reply	other threads:[~2005-01-17 17:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-15 21:22 Are string literals _always_ allocated in the RO section? Denis Zaitsev
2005-01-15 21:27 ` Dale Johannesen
2005-01-15 21:41 ` Denis Zaitsev
2005-01-15 23:18 ` Gabriel Dos Reis
2005-01-17 17:18   ` Jan-Benedict Glaw [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050117171853.GG28037@lug-owl.de \
    --to=jbglaw@lug-owl.de \
    --cc=linux-gcc@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).