Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: modifying local const variable run time Date: Wed, 22 Feb 2017 15:20:52 -0800 Organization: None to speak of Lines: 23 Message-ID: References: <20170222160611.91c1f3085d6c9e3571a68156@gmail.com> <3cba5f3c-735a-45b7-87f2-d03dd8a18720@googlegroups.com> <20170222173450.4fe314b3c852b242bb2dc35a@gmail.com> <20170222183223.a4daa256d17cc9bfcc04d4b9@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="17193b87357f3199fd5654843cb49d05"; logging-data="3703"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19js1072Zgn97TzNoeax7ta" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:7gV+JvUm84nlxEx6xJFWLVfM89Q= sha1:HqiXqTHObLIBLNARvxxnYs0Tb3Q= Xref: csiph.com comp.lang.c:104414 David Brown writes: > On 22/02/17 18:50, Keith Thompson wrote: [...] >> Personally, I use "const" mostly to make code clearer, so it's >> obvious at a glance to a human reader that a given object won't >> be modified, and so that the compiler can diagnose any incorrect >> attempt to modify it. If a compiler can use that information to >> generate faster code, so much the better. > > Or more importantly, if the compiler can use that information to spot > mistakes in the code - accidentally modifying the const object - then so > much the better. That's why the "const" keyword is much better than a > "const" comment would have been, even if the comment were equally > readable to humans. I believe you're repeating part of what I wrote: "... and so that the compiler can diagnose any incorrect attempt to modify it". -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"