Re: Const correctness
Re: Const correctness
- Subject: Re: Const correctness
- From: Clark Cox <email@hidden>
- Date: Thu, 9 Jun 2005 07:49:42 -0400
On 6/9/05, Markian Hlynka <email@hidden> wrote:
> >>
> >> 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. ;-)
This has nothing to do with the heap or the stack. It is simply
because the C and C++ standards say that attempting to modify a string
literal is undefined behavior.
--
Clark S. Cox III
email@hidden
http://www.livejournal.com/users/clarkcox3/
http://homepage.mac.com/clarkcox3/
_______________________________________________
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