Path: csiph.com!weretis.net!feeder8.news.weretis.net!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c++ Subject: Re: I think references should have been const by default Date: Mon, 25 Oct 2021 10:48:57 -0700 Organization: None to speak of Lines: 40 Message-ID: <87bl3d2dx2.fsf@nosuchdomain.example.com> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="ce9c6a8e39b023180b9e14b2203de6ab"; logging-data="1558"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18vn0Ti77+CYZ87PfpAMTcE" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:4L4lU9+YJ72WRP+batijZwFB0aE= sha1:QyoDvHTBc4FWTQvP2VLPAA7v19c= Xref: csiph.com comp.lang.c++:82080 RacingRabbit@watershipdown.co.uk writes: > On Mon, 25 Oct 2021 10:59:15 -0400 > James Kuyper wrote: >>On 10/25/21 10:19 AM, RacingRabbit@watershipdown.co.uk wrote: >>>> call it with a pointer that's pointing to a string literal. If said >>>> function does modify the "string" it's getting as parameter, that's UB. >>> >>> No idea what UB means, but what'll happen is it'll crash immediately so >>you'll >>> soon find out. >> >>UB means "Undefined Behavior", a technical term from the C standard >>which does NOT mean "behavior for which there is no definition". It >>means "behavior, upon use of a nonportable or erroneous program >>construct or of erroneous data, for which this document imposes no >>requirements" (3.4.3). Note that "this document" refers to the C >>standard; other documents (such as compiler documentation or ABI >>standards) might define the behavior, without changing the fact that is >>qualifies as "undefined behavior" as far as the C standard is concerned. > > Any attempt to write to a read only program text area will result in a crash > regardless of the language. It is implicit that its read only in C because > C also provides the following initialisation which places the string > (presumably) on the heap: > > char str[] = "hello world"; I suggest that you would benefit more here from asking questions than from making assertions. That declaration does not place anything on the heap. The contents of str is placed on the stack if it appears within a function definition. or in the static data area if it appears outside a function definition. Others have addresses your errors regarding "const". -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for Philips void Void(void) { Void(); } /* The recursive call of the void */