Re: const and static (was: C vs. assembly...)

cdg@nullstone.com (Christopher Glaeser)
12 Apr 1996 09:10:58 -0400

          From comp.compilers

Related articles
[3 earlier articles]
Re: const and static (was: C vs. assembly...) cdg@nullstone.com (1996-03-27)
Re: const and static (was: C vs. assembly...) mason@ease.com (1996-03-29)
Re: const and static (was: C vs. assembly...) cdg@nullstone.com (1996-04-02)
Re: const and static (was: C vs. assembly...) jmccarty@sun1307.spd.dsccc.com (1996-04-02)
Re: const and static (was: C vs. assembly...) KingD@rnd1.indy.tce.com (King Dale) (1996-04-11)
Re: const and static (was: C vs. assembly...) cdg@nullstone.com (1996-04-12)
Re: const and static (was: C vs. assembly...) cdg@nullstone.com (1996-04-12)
Re: const and static (was: C vs. assembly...) sharris@fox.nstn.ca (1996-04-13)
Re: const and static (was: C vs. assembly...) mfinney@inmind.com (1996-04-16)
Re: const and static (was: C vs. assembly...) schwarz@mips.complang.tuwien.ac.at (1996-04-18)
| List of all articles for this month |

From: cdg@nullstone.com (Christopher Glaeser)
Newsgroups: comp.compilers
Date: 12 Apr 1996 09:10:58 -0400
Organization: Compilers Central
References: 96-03-106 96-03-181 96-03-202 96-04-021
Keywords: C, optimize, performance

Mike McCarty <jmccarty@sun1307.spd.dsccc.com> writes:


> This in reply to what Christopher seems to be saying. In my mind, the
> real reason for "const" to exist in C has nothing to do with the
> conversation you are having. It has to do with pointers used as
> arguments to routines which must read the areas pointed to, but which
> are not intended to modify them.


My remarks were focused on 1) optimizations that the C standard allows
regarding const, 2) how some programmers use the language and their
expectations of efficiency, and 3) the current state of production
compilers wrt const optimization. "The real reason" a feature exists
is drifting into coding style, a subjective topic that, even after
considerable honest debate, rarely changes anyone's mind.


Regardless of "The real reason for const to exist in C", there is
ample evidence that many C programmers use const as a replacement for
#define, and furthermore, that they expect the code to be as efficient
as #define.


Consider the book "C Elements of Style" by Steve Oualline, in which he
discusses the various advantages of const over #define. Steve
concludes this discussion with Rule 6-4: "The use of const is
preferred over #define for specifying constants." Other texts on the
C language and C programming offer similar advice.


I do not cite this reference with any expectation or desire to
convince you of the reasons why const was introduced into the
language. Rather, I'm using this citation to show that a body
programmers use the language in this way, an important point to
consider when deciding which optimizations to implement in a compiler.


Best regards,
Christopher Glaeser cdg@nullstone.com
Nullstone Corporation http://www.nullstone.com
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.