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

mfinney@inmind.com
16 Apr 1996 22:26:22 -0400

          From comp.compilers

Related articles
[5 earlier articles]
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: mfinney@inmind.com
Newsgroups: comp.compilers
Date: 16 Apr 1996 22:26:22 -0400
Organization: In Mind, Inc.
References: 96-03-106 96-04-081 96-04-086
Keywords: C

Christopher Glaeser <cdg@nullstone.com> wrote:
>. . . many C programmers use const as a replacement for
>#define, and . . . expect the code to be as efficient as #define.


sharris@fox.nstn.ca> writes:
>Good grief.


In C++, using const instead of a #define is strongly recommended by
most authors, and is suggested in more than one place in ARM. So many
programmers are perfectly justified in expecting that const be
implemented at zero overhead cost in most circumstances.


Unfortunately, it is NOT implemented reasonably in many compilers.
And, worse, many compilers (especially in C++) will generate a
different copy of each const variable in each source file. Even if
not referenced in that source file. So you get both time and space
penalities for using const.


But, still, the programmer is justified in assuming that it SHOULD be
implemented efficiently even if the current set of compilers are not
so nice in this area.


It is also generally recommended that inline be used instead of
#define macro definitions -- and again, the compiler is free to ignore
the inline qualifier. If the programmer wants something inlined,
const or function, the ONLY way to ensure that is to use the
preprocessor.
--


Post a followup to this message

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