string literals

Discussion in 'C Programming' started by Tech07, Oct 12, 2009.

  1. Tech07

    Tech07 Guest

    Why can't I change them? Apparently someone is walking the fence and doesn't
    know. Hmm? Ask him! (BTW, I know why).
     
    Tech07, Oct 12, 2009
    #1
    1. Advertisements

  2. On 12 Oct, 07:21, "Tech07" <> 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>
     
    Nick Keighley, Oct 12, 2009
    #2
    1. Advertisements

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

    Nick Keighley wrote:

    > On 12 Oct, 07:21, "Tech07" <> 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)

    iEYEARECAAYFAkrTOh4ACgkQG6NzcAXitM9eBACfTZgW8WXA5Tu5ZXXMIYqYupLB
    XRUAn3y91zFjXYwKYwJgwh1D8kApVK4j
    =euxR
    -----END PGP SIGNATURE-----
     
    Michael Tsang, Oct 12, 2009
    #3
  4. snipped PGP stuff

    On 12 Oct, 15:15, Michael Tsang <> wrote:
    > Nick Keighley wrote:
    > > On 12 Oct, 07:21, "Tech07" <> 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.
     
    Nick Keighley, Oct 12, 2009
    #4
  5. Tech07

    Seebs Guest

    Seebs, Oct 12, 2009
    #5
  6. Tech07

    James Kuyper Guest

    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.
     
    James Kuyper, Oct 12, 2009
    #6
  7. Tech07

    Tech07 Guest

    Nick Keighley wrote:
    > On 12 Oct, 07:21, "Tech07" <> 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.
     
    Tech07, Oct 13, 2009
    #7
  8. Tech07

    Tech07 Guest

    Nick Keighley wrote:
    > snipped PGP stuff
    >
    > On 12 Oct, 15:15, Michael Tsang <> wrote:
    >> Nick Keighley wrote:
    >>> On 12 Oct, 07:21, "Tech07" <> 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".
     
    Tech07, Oct 13, 2009
    #8
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Harri Pesonen

    String literals in Java

    Harri Pesonen, May 28, 2004, in forum: Java
    Replies:
    59
    Views:
    15,441
    Jim Cochrane
    Jun 2, 2004
  2. Pete Elmgreen

    character literals and string

    Pete Elmgreen, Nov 24, 2004, in forum: Java
    Replies:
    3
    Views:
    4,864
  3. Purush
    Replies:
    4
    Views:
    1,889
    Purush Rudrakshala
    Apr 13, 2005
  4. Replies:
    4
    Views:
    921
    Roedy Green
    Nov 21, 2005
  5. John Goche
    Replies:
    8
    Views:
    16,749
Loading...

Share This Page