Topic: manifest constants


Author: swf@tdat.ElSegundoCA.NCR.COM (Stan Friesen)
Date: Tue, 14 Dec 93 11:16:22 PST
Raw View
In article <755615510snz@vsfl.demon.co.uk>, clint@vsfl.demon.co.uk writes:
|> However, what happens with const aggregates?  Isn't it true (I
|> can't seem to find a clear statement on this in Sproutstrap,
|> must be looking in the wrong place) that const aggregates, as in
|>
|>     const char *fred = "hello";
|>
|> *do* normally have store allocated for them?  In that case, "inline"
|> might make sense.  Mightn't it?

You may be right, but your example does not match what you are talking
about.  Your example is of a *scalar* pointer to an anonymous const
agregate.

 const char fred[] = "hello";

is closer to what you are talking about.

However, I see no way to *use* such an agregate that does not
require memory allocation, so I am still not sure 'inline' buys
you anything with const data.

--
sarima@elsegundoca.ncr.com   (formerly tdatirv!sarima)
  or
Stanley.Friesen@ElSegundoCA.ncr.com

The peace of God be with you.




Author: swf@tdat.ElSegundoCA.NCR.COM (Stan Friesen)
Date: Fri, 10 Dec 93 08:54:10 PST
Raw View
In article <1993Dec8.025519.7110@sat.mot.com>, hall_j@sat.mot.com (Joseph Hall) write:
|> A friend of mine and I were kicking around something like the following
|> on the phone yesterday:
|>
|>   inline const double pi = 3.14159;
|>   inline const double ee = 2.71828;

And just how is this supposed to be different than:

 const double pi = 3.14159;
 const double ee = 2.71828;
?
As far as I can see, *any* const variable can be 'inlined'
in the only sense that I can figure out.

--
sarima@teradata.com   (formerly tdatirv!sarima)
  or
Stanley.Friesen@ElSegundoCA.ncr.com

The peace of God be with you.




Author: hall_j@sat.mot.com (Joseph Hall)
Date: Fri, 10 Dec 1993 21:18:43 GMT
Raw View
Seems it was swf@tdat.ElSegundoCA.NCR.COM who said:
>In article <1993Dec8.025519.7110@sat.mot.com>, hall_j@sat.mot.com (Joseph Hall) write:
>|> A friend of mine and I were kicking around something like the following
>|> on the phone yesterday:
>|>
>|>   inline const double pi = 3.14159;
>|>   inline const double ee = 2.71828;
>
>And just how is this supposed to be different than:
>
> const double pi = 3.14159;
> const double ee = 2.71828;

Well, for one, no storage would be allocated.  I'm thinking of a
non-preprocessor means of having

  #define pi 3.14159

--
Joseph Nathan Hall |  Whales: smart food for smart people
Software Architect |    (* for the extremely humor-impaired, this is a joke)
Gorca Systems Inc. |                 joseph@joebloe.maple-shade.nj.us (home)
(on assignment)    |         (602) 732-2549 (work)   Joseph_Hall@sat.mot.com




Author: clint@vsfl.demon.co.uk (Ian Cameron Smith)
Date: Sat, 11 Dec 1993 13:11:50 +0000
Raw View
In article <1993Dec10.211843.9435@sat.mot.com> hall_j@sat.mot.com writes:

> Seems it was swf@tdat.ElSegundoCA.NCR.COM who said:
> >In article <1993Dec8.025519.7110@sat.mot.com>, hall_j@sat.mot.com (Joseph
>  Hall) write:
> >|> A friend of mine and I were kicking around something like the following
> >|> on the phone yesterday:
> >|>
> >|>   inline const double pi = 3.14159;
> >|>   inline const double ee = 2.71828;
> >
> >And just how is this supposed to be different than:
> >
> >       const double pi = 3.14159;
> >       const double ee = 2.71828;
>
> Well, for one, no storage would be allocated.  I'm thinking of a
> non-preprocessor means of having
>
>   #define pi 3.14159

As I understand it, any decent compiler will do this anyway; ie. no
storage will be allocated for int or float consts; the values
will simply be dropped into the code when used, as for #define.

However, what happens with const aggregates?  Isn't it true (I
can't seem to find a clear statement on this in Sproutstrap,
must be looking in the wrong place) that const aggregates, as in

    const char *fred = "hello";

*do* normally have store allocated for them?  In that case, "inline"
might make sense.  Mightn't it?
--
Ian Cameron Smith                clint@vsfl.demon.co.uk
Principal Software Engineer      +44 (0)425 474484
Virtual Software Factory LTD

"Go ahead, punk, make my day"




Author: hall_j@sat.mot.com (Joseph Hall)
Date: Wed, 8 Dec 1993 02:55:19 GMT
Raw View
A friend of mine and I were kicking around something like the following
on the phone yesterday:

  inline const double pi = 3.14159;
  inline const double ee = 2.71828;

Or, generally (and imprecisely):

  inline const [initialized declaration]

as a means of declaring manifest constants of particular types.  How, or
whether, this would work for constructed classes (say, if the constructor
contained only initializers) ...

Comments?

I also suggested:

  inline double Pi() { return 3.14159; }

as a legal method of achieving much the same end, although the syntax
is ugly.  I also doubt that return values from inline functions returning
constant values are typically treated as compile-time constants.

--
Joseph Nathan Hall |  Whales: smart food for smart people
Software Architect |
Gorca Systems Inc. |                 joseph@joebloe.maple-shade.nj.us (home)
(on assignment)    |         (602) 732-2549 (work)   Joseph_Hall@sat.mot.com