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

King Dale <KingD@rnd1.indy.tce.com>
11 Apr 1996 23:31:20 -0400

          From comp.compilers

Related articles
[3 earlier articles]
const and static (was: C vs. assembly...) mark@omnifest.uwm.edu (1996-03-25)
const and static (was: C vs. assembly...) fjh@cs.mu.OZ.AU (1996-03-27)
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: King Dale <KingD@rnd1.indy.tce.com>
Newsgroups: comp.compilers
Date: 11 Apr 1996 23:31:20 -0400
Organization: Compilers Central
References: 96-03-106 96-03-006 96-03-091 96-03-181
Keywords: C

mark@omnifest.uwm.edu (Mark Hopkins) wrote:


> However, I agree with you on the "const" feature -- but for different
> reasons. Not only should the compilers be using the "const" feature,
> but it shouldn't even have to have it because it should already be
> doing expression evaluations to reduce all those expressions that can
> be reduced at compile-time.
>
> In the example you cite:
> > #define ONE 1
> > const int one = 1;
> >
> > int f()
> > {
> > x = ONE;
> > y = one;
> > }
>
> this should compile to exactly the same thing as the following does:
>
> int f() { x = 1; y = 1; }


And if it does, you should quickly demand your money back for that
compiler. Const does not mean that this variable is to be treated as a
compile time constant. What it means is that the user of this
definition cannot modify it. That doesn't mean some other routine
won't.


As an example consider if you had some library and wanted to provide a
read only variable to users of the library. You could put an extern
const type var; in an include file for the outside world, but internal
to the library, use it without the const.


Unfortunately, C will let someone overwrite it by just making their
own extern type var;. Heck, C doesn't even care if you access it with
a completely bogus type. A good strongly-typed language should be
designed to not allow this. This lack of data hiding and strong type
checking are some of the reasons that C is really not a very good
language.


--


Post a followup to this message

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