comp.lang.ada
 help / color / mirror / Atom feed
* Constants: how are they allocated?
@ 1996-05-01  0:00 Justin Gombos
  1996-05-02  0:00 ` Chad Bremmon
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Justin Gombos @ 1996-05-01  0:00 UTC (permalink / raw)



When a constant is assigned to a variable, is the constant stored on the 
stack, or in the heap?





^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Constants: how are they allocated?
  1996-05-01  0:00 Constants: how are they allocated? Justin Gombos
@ 1996-05-02  0:00 ` Chad Bremmon
  1996-05-02  0:00 ` Theodore E. Dennison
  1996-05-06  0:00 ` justin gombos
  2 siblings, 0 replies; 7+ messages in thread
From: Chad Bremmon @ 1996-05-02  0:00 UTC (permalink / raw)



Justin Gombos wrote:
> 
> When a constant is assigned to a variable, is the constant stored on the
> stack, or in the heap?When a constant is assigned to a variable, the constant will not move or change. I believe that 
where the variable goes is compiler defined.  Common practice places non-dynamic variables on the 
stack.

Chad




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Constants: how are they allocated?
  1996-05-01  0:00 Constants: how are they allocated? Justin Gombos
  1996-05-02  0:00 ` Chad Bremmon
@ 1996-05-02  0:00 ` Theodore E. Dennison
  1996-05-06  0:00 ` justin gombos
  2 siblings, 0 replies; 7+ messages in thread
From: Theodore E. Dennison @ 1996-05-02  0:00 UTC (permalink / raw)



Justin Gombos wrote:
> 
> When a constant is assigned to a variable, is the constant stored on the
> stack, or in the heap?

That depends on your compiler, and on how and where the constant was
declared.

Your compiler's docs (if they are any good) should shed light on this.

I know in VADS's case it LOOKS LIKE constants that aren't "static" are
meerly variables that the compiler won't let you update. They have
'ADDRESSes, and are stored in the same place a variable would be:
    On the heap if they are global to a package or the main routine.
    On the stack if they are in the body of a task or subprogram.

Constants that are static are meerly textually replaced by their value
at run-time.

If I remember correctly, DEC Ada handles constants quite differently.

-- 
T.E.D.          
                |  Work - mailto:dennison@escmail.orl.mmc.com  |
                |  Home - mailto:dennison@iag.net              |
                |  URL  - http://www.iag.net/~dennison         |




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Constants: how are they allocated?
  1996-05-06  0:00   ` Robert A Duff
@ 1996-05-06  0:00     ` Theodore E. Dennison
  0 siblings, 0 replies; 7+ messages in thread
From: Theodore E. Dennison @ 1996-05-06  0:00 UTC (permalink / raw)



Robert A Duff wrote:
> 
> In article <4ml2s6$bis@dewey.csun.edu>,
> justin gombos <hbcsc096@csun.edu> wrote:
> >Oops.. I botched on the question.  Let me re-word it.  If a constant is
> >defined and allocated at runtime, where is it stored?  ie. in the case
> >that a constant is assigned to a function or expression containing
> >variables.
> 
> In most compilers, such constants are allocated just like variables.

Unless, of course, the constant is static (on some compilers). And of
course some compilers go a bit beyond the LRM definition of "static"
in deciding which constants to treat this way.

Again, this is all really implementation-defined.

-- 
T.E.D.          
                |  Work - mailto:dennison@escmail.orl.mmc.com  |
                |  Home - mailto:dennison@iag.net              |
                |  URL  - http://www.iag.net/~dennison         |




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Constants: how are they allocated?
  1996-05-01  0:00 Constants: how are they allocated? Justin Gombos
  1996-05-02  0:00 ` Chad Bremmon
  1996-05-02  0:00 ` Theodore E. Dennison
@ 1996-05-06  0:00 ` justin gombos
  1996-05-06  0:00   ` Robert A Duff
  1996-05-06  0:00   ` Theodore E. Dennison
  2 siblings, 2 replies; 7+ messages in thread
From: justin gombos @ 1996-05-06  0:00 UTC (permalink / raw)



Oops.. I botched on the question.  Let me re-word it.  If a constant is
defined and allocated at runtime, where is it stored?  ie. in the case
that a constant is assigned to a function or expression containing
variables. 

--
http://www.csun.edu/~hbcsc096/dt




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Constants: how are they allocated?
  1996-05-06  0:00 ` justin gombos
  1996-05-06  0:00   ` Robert A Duff
@ 1996-05-06  0:00   ` Theodore E. Dennison
  1 sibling, 0 replies; 7+ messages in thread
From: Theodore E. Dennison @ 1996-05-06  0:00 UTC (permalink / raw)



justin gombos wrote:
> 
> Oops.. I botched on the question.  Let me re-word it.  If a constant is
> defined and allocated at runtime, where is it stored?  ie. in the case
> that a constant is assigned to a function or expression containing
> variables.

The answer is still the same. This is not something defined in the 
language's specification, so it is up to the compiler writer. Your
compiler's documentation may contain this information. No one here
can give you a definitive answer without knowing what Ada compiler
(vendor and platform) you are talking about.

-- 
T.E.D.          
                |  Work - mailto:dennison@escmail.orl.mmc.com  |
                |  Home - mailto:dennison@iag.net              |
                |  URL  - http://www.iag.net/~dennison         |




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Constants: how are they allocated?
  1996-05-06  0:00 ` justin gombos
@ 1996-05-06  0:00   ` Robert A Duff
  1996-05-06  0:00     ` Theodore E. Dennison
  1996-05-06  0:00   ` Theodore E. Dennison
  1 sibling, 1 reply; 7+ messages in thread
From: Robert A Duff @ 1996-05-06  0:00 UTC (permalink / raw)



In article <4ml2s6$bis@dewey.csun.edu>,
justin gombos <hbcsc096@csun.edu> wrote:
>Oops.. I botched on the question.  Let me re-word it.  If a constant is
>defined and allocated at runtime, where is it stored?  ie. in the case
>that a constant is assigned to a function or expression containing
>variables. 

In most compilers, such constants are allocated just like variables.
The fact that the thing is constant causes compile-time checks, and
might cause the optimizer to be more clever, but is unlikely to affect
storage allocation (I'm assuming the compiler doesn't know the value
here).

E.g if you put:

    X: constant Integer := Read_A_Value_From_The_Keyboard;

in a procedure, X will probably be allocated on the stack, just the same
as if X were not constant.

- Bob




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~1996-05-06  0:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-05-01  0:00 Constants: how are they allocated? Justin Gombos
1996-05-02  0:00 ` Chad Bremmon
1996-05-02  0:00 ` Theodore E. Dennison
1996-05-06  0:00 ` justin gombos
1996-05-06  0:00   ` Robert A Duff
1996-05-06  0:00     ` Theodore E. Dennison
1996-05-06  0:00   ` Theodore E. Dennison

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox