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 09:50:08 -0800 Organization: None to speak of Lines: 28 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="49aa0a1b7995c9119124e44e55d9580d"; logging-data="26730"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19zYjUoOVFuJciL/1xGTKqM" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:vdhxF+jUdIMrLE3HFUTRuqbODgI= sha1:h8aaMmU4jdDY6xaIXnasu+Od4Co= Xref: csiph.com comp.lang.c:104390 GOTHIER Nathan writes: > On Wed, 22 Feb 2017 09:23:50 -0800 > Keith Thompson wrote: > >> "const" means read-only. > > Should we assume that this keyword only provide warnings on assignments with > zero optimization? I'm not sure what that means. The "const" keyword does not specify any kind of optimization. It imposes constraints on code that code that refers to const-qualified objects and types. A compiler can take advantage of those constraints for purposes of optimization, but is not required to do so. In many cases, a compiler can perform exactly the same optimizations without the "const" keyword, if it's able to infer the same information. 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. -- 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"