Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Bo Persson Newsgroups: comp.lang.c++ Subject: Re: I think references should have been const by default Date: Mon, 25 Oct 2021 12:33:37 +0200 Lines: 19 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net gfSmQx3Qnt39gmd9VehUxQ8+VM2hAJPmiN2rNDGIlmZNJ3PZ2G Cancel-Lock: sha1:wYSNUa7e81t3eI5k0vrquRwd0g8= User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 In-Reply-To: Content-Language: sv Xref: csiph.com comp.lang.c++:82067 On 2021-10-25 at 11:47, Juha Nieminen wrote: > RacingRabbit@watershipdown.co.uk wrote: >> Consts in C are pointless because it doesn't have references and its rather >> difficult to "accidentaly" dereference a pointer to update the value its >> pointing to. > > Actually it isn't. Very old-style C code, mostly prior to the C89 standard, > but you can see even modern examples sometimes (for some old-school C coders > habits die hard), often used non-const pointers to char as "strings". > In fact, I think even the K&R famous book as examples with non-const char*'s > being initialized to point to string literals. > In defense of K&R. :-) They didn't have const in original C. It was Bjarne who first added it to C++, and only later did C also adopt the keyword.