Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: "...the value becomes,indeterminate each time the declaration is reached" Date: Thu, 07 Feb 2019 10:33:39 -0800 Organization: None to speak of Lines: 50 Message-ID: References: <5c51d4fb.236542547@news.xmission.com> <20190201132441.0b099e5f38fdb72371bc44f0@g{oogle}mail.com> <20190204120834.7d3f84f25052b6a8315f693a@g{oogle}mail.com> <4c59dca0-2449-4234-a935-b6d604088caf@googlegroups.com> <84b47866-600b-48d2-85b6-1538f19b00df@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="f376dcb2b82f2c4f0e13c019c6c4653e"; logging-data="8122"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+jSIzYQUUdDvHAUJ8B2kSB" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:klbMSUVd1iunwFl98L47eGeru5U= sha1:0ZU79FwYkSojzHiWCD8rP/F6rCk= Xref: csiph.com comp.lang.c:140739 Malcolm McLean writes: > On Tuesday, 5 February 2019 21:14:28 UTC, Keith Thompson wrote: >> Malcolm McLean writes: >> > On Tuesday, 5 February 2019 19:23:26 UTC, Ian Collins wrote: >> >> You are being willfully obtuse, const in C++ is a significant >> >> improvement over const in C. >> >> >> > It's significantly more complex. >> > >> > It's no longer true, as it is in C, that a correct program cannot >> > be turned into an incorrect program by const-qualifying or const- >> > dequalifying identifiers. >> >> Can you clarify what you mean by that? >> >> I can turn this correct program: >> >> int main(void) { >> int n = 10; >> n = 20; >> } >> >> into an incorrect program by const-qualifying n. >> > What I (actually Dennis Ritchie) meant is this. > > We have > > double total_salaries(const Employee *emp, int N); > > The function works, and it doesn't corrupt the employee array. > Now we can take the const away, and the function must still work > correctly. We can add it again, and it still works correctly. If I have a call like this: const Employee staff[42]; double cost = total_salaries(staff, 42); then removing the "const" from the parameter declaration makes the program incorrect. I think that if you remove *all* occurrences of "const" from a correct program, the result is still a correct program (though removing "const" makes it easier to make the program incorrect). -- Keith Thompson (The_Other_Keith) kst-u@mib.org Will write code for food. void Void(void) { Void(); } /* The recursive call of the void */