• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Const correctness
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Const correctness


  • Subject: Re: Const correctness
  • From: Markian Hlynka <email@hidden>
  • Date: Wed, 8 Jun 2005 22:34:17 -0600


And the runtime crash in the above example has absolutely nothing to do with 'const' and everything to do with trying to change an embedded string. I.e. the following crashes exactly the same: char* noConstsAreBetter = "these consts suck\n"; printf( noConstsAreBetter ); noConstsAreBetter[0] = 'T'; printf( noConstsAreBetter );


I seem to recall this is because literals like this are allocated on the heap, not the stack. That's why bad things happen when you try to change it. The heap is not for you. ;-)


Do I remember correctly?

Markian

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Const correctness
      • From: Clark Cox <email@hidden>
References: 
 >Const correctness (From: "Theodore H. Smith" <email@hidden>)
 >Re: Const correctness (From: Cameron Hayne <email@hidden>)
 >Re: Const correctness (From: Keith Ray <email@hidden>)

  • Prev by Date: Re: Xcode 2.1 --- strings passed as -DMY_STRING="mystring"
  • Next by Date: Intel and x64 Question
  • Previous by thread: Re: Const correctness
  • Next by thread: Re: Const correctness
  • Index(es):
    • Date
    • Thread