string literals

T

Tech07

Why can't I change them? Apparently someone is walking the fence and doesn't
know. Hmm? Ask him! (BTW, I know why).
 
N

Nick Keighley

you should try to make your posts "standalone". Please include the
subject in the
body of your post.
Why can't I change [string literals]?

because the standard says it is undefined behaviour to modify a string
literal.
Many platforms take advantage of this and put string literals in ROM
or other
read-protected address space.

<snip Tech gibberish>
 
M

Michael Tsang

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Nick said:
you should try to make your posts "standalone". Please include the
subject in the
body of your post.
Why can't I change [string literals]?

because the standard says it is undefined behaviour to modify a string
literal.
Many platforms take advantage of this and put string literals in ROM
or other
read-protected address space.

<snip Tech gibberish>
Because a string literal is a "const char[]"
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkrTOh4ACgkQG6NzcAXitM9eBACfTZgW8WXA5Tu5ZXXMIYqYupLB
XRUAn3y91zFjXYwKYwJgwh1D8kApVK4j
=euxR
-----END PGP SIGNATURE-----
 
N

Nick Keighley

snipped PGP stuff

Nick said:
On 12 Oct, 07:21, "Tech07" <[email protected]> wrote:
Why can't I change [string literals]?
because the standard says it is undefined behaviour to modify a string
literal.
Many platforms take advantage of this and put string literals in ROM
or other read-protected address space.
<snip Tech gibberish>

Because a string literal is a "const char[]"

no it isn't. A string is still a char* but it is undefined behaviour
to modify it. C++ may have different rules but these are the C rules.
 
J

James Kuyper

Michael Tsang wrote:
....
Because a string literal is a "const char[]"

Those are the C++ rules. This is comp.lang.c. You made exactly the same
mistake on 9/29, and two similar mistakes on 10/7. Please pay more
attention to the differences between these two languages.
 
T

Tech07

Nick said:
you should try to make your posts "standalone". Please include the
subject in the
body of your post.
Why can't I change [string literals]?

because the standard says

Good answer. Not necessarily right, but it is the vehicle of the gestapo.
it is undefined behaviour to modify a string
literal.

Is that limeric? On what platform? With what compiler? Apparently your
politics are just that. Hmm?
Many platforms

Oh. A PLATFORM. So you actually know what that is. Trully interesting.
take advantage of this and put string literals in ROM
or other
read-protected address space.

I think that may have relevance/value. Until I kow that though, I'm coding
around it.
<snip Tech gibberish>

I do do that.
 
T

Tech07

Nick said:
snipped PGP stuff

Nick said:
On 12 Oct, 07:21, "Tech07" <[email protected]> wrote:
Why can't I change [string literals]?
because the standard says it is undefined behaviour to modify a
string literal.
Many platforms take advantage of this and put string literals in ROM
or other read-protected address space.
<snip Tech gibberish>

Because a string literal is a "const char[]"

no it isn't. A string is still a char* but it is undefined behaviour
to modify it. C++ may have different rules but these are the C rules.

I'm going to do it tomorrow. OK, maybe Wednesday, but I assure you I am
going to do it. I will hold off on doing it unless there is world wide
agreement that I can conduct such nuclear testing. I am going to attempt to
.... (whew, this is tough)... I am going to write to a string literal. I
want Natalie to know (she doesn't care) that I loved her a lot from afar.
Sarah, you are a princess, and I do love you. Y'all do what you want or have
to do, but come Wednesday, I'm going to write to a string literal. "God help
us all".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top