Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > string literals

Reply
Thread Tools

string literals

 
 
Tech07
Guest
Posts: n/a
 
      10-12-2009
Why can't I change them? Apparently someone is walking the fence and doesn't
know. Hmm? Ask him! (BTW, I know why).


 
Reply With Quote
 
 
 
 
Nick Keighley
Guest
Posts: n/a
 
      10-12-2009
On 12 Oct, 07:21, "Tech07" <tec...@nospam.hia> wrote:

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>
 
Reply With Quote
 
 
 
 
Michael Tsang
Guest
Posts: n/a
 
      10-12-2009
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Nick Keighley wrote:

> On 12 Oct, 07:21, "Tech07" <tec...@nospam.hia> wrote:
>
> 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)

iEYEARECAAYFAkrTOh4ACgkQG6NzcAXitM9eBACfTZgW8WXA5T u5ZXXMIYqYupLB
XRUAn3y91zFjXYwKYwJgwh1D8kApVK4j
=euxR
-----END PGP SIGNATURE-----

 
Reply With Quote
 
Nick Keighley
Guest
Posts: n/a
 
      10-12-2009
snipped PGP stuff

On 12 Oct, 15:15, Michael Tsang <mikl...@gmail.com> wrote:
> Nick Keighley wrote:
> > On 12 Oct, 07:21, "Tech07" <tec...@nospam.hia> 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.
 
Reply With Quote
 
Seebs
Guest
Posts: n/a
 
      10-12-2009
On 2009-10-12, Michael Tsang <> wrote:
> Because a string literal is a "const char[]"


Not in C.

There's no const qualifier, just something it's undefined behavior to modify.

-s
--
Copyright 2009, all wrongs reversed. Peter Seebach / usenet-
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
 
Reply With Quote
 
James Kuyper
Guest
Posts: n/a
 
      10-12-2009
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.
 
Reply With Quote
 
Tech07
Guest
Posts: n/a
 
      10-13-2009
Nick Keighley wrote:
> On 12 Oct, 07:21, "Tech07" <tec...@nospam.hia> wrote:
>
> 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.


 
Reply With Quote
 
Tech07
Guest
Posts: n/a
 
      10-13-2009
Nick Keighley wrote:
> snipped PGP stuff
>
> On 12 Oct, 15:15, Michael Tsang <mikl...@gmail.com> wrote:
>> Nick Keighley wrote:
>>> On 12 Oct, 07:21, "Tech07" <tec...@nospam.hia> 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".


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java: byte literals and short literals John Goche Java 8 01-17-2006 11:12 PM
Unicode String Literals didster@gmail.com Java 4 11-21-2005 11:43 AM
Generic class literals - e.g,, Class<Map<String, Integer>>.class Purush Java 4 04-13-2005 08:40 PM
character literals and string Pete Elmgreen Java 3 11-24-2004 04:42 PM
String literals in Java Harri Pesonen Java 59 06-02-2004 08:00 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57