[comp.lang.pascal] TP50: Typed constants

pilgrimk@lafcol.UUCP (Kenwyn A. Pilgrim) (07/20/89)

Today I discovered something really bizarre.
I had two typed constants which looked like

const
   CompOne : integer = 10;
   CompTwo : integer = 15;

The value of these were changed just once in the program

   CompOne := 4;
   CompTwo := 7;

So far so good.

While running my program, I discovered that the variables
CompOne & CompTwo didn't contain the values 4 and 7 respectively,
but some values (they were actually values of some other typed
constants). [I'm using graphics and haven't yet figured out how 
to debug while in graphics mode :-( ]

After some fooling around, I decided to make these typed
constants 'variables', i.e.

 var
  CompOne : integer;
  CompTwo : integer;

and lo and behold, they didst come up with the values expected,
namely 4 and 7.

My question is:
  Is there a limit to the no. of typed constants?
  (my data size was < 2K bytes according to the Get Info option)

or what else do you think is wrong?

Remember, these variables were initialized only once and never
again were they operated on - implicitly or explicitly.
Your help would be appreciated.

-Kenwyn

taylorj@yvax.byu.edu (07/22/89)

I'm 99.9% sure it's your fault and not Turbo Pascal's.  You probably have
uninitialized pointers and are writing over the top of the area in memory where
the typed constants are stored.  When you changed them to variables they were
stored in a different place, so they didn't get written over (but something
else probably did!).   This type of behavior can also occur if you pass too
small a buffer to some procedures such as GetImage, BlockRead, etc.  Use the
debugger (or put in lot's of writelns) and find out exactly when in your
program the constants are being changed.

Jim Taylor
Microcomputer Support for Curriculum   |
Brigham Young University               |   Bitnet: taylorj@byuvax.bitnet
101 HRCB, Provo, UT  84602             |   Internet: taylorj@yvax.byu.edu

tom@stiatl.UUCP (Tom Wiencko) (07/22/89)

In article <1356@lafcol.UUCP> pilgrimk@lafcol.UUCP (Kenwyn A. Pilgrim) writes:
>Today I discovered something really bizarre.
>I had two typed constants which looked like
> ...
>My question is:
>  Is there a limit to the no. of typed constants?
>  (my data size was < 2K bytes according to the Get Info option)
>
>or what else do you think is wrong?
>
>-Kenwyn


Likely what has happened is that you are wiping out these memory locations
with some other modification of a typed constant.  A typed constant is 
not really much more than an initialized data area, and does not have any
size or count restrictions that I have ever read about or run into (and
I have some programs with lots and lots of typed constants).

First place I'd look is for pointers running away or some such like that.
The problem probably went away when you declared these items as variables 
because you changed their memory location.  A quick way to check this would
be to declare some large typed constants (large in size, not value) before
and after the affected constants and see if they are still getting clobbered.

This is a wonderful place to use the Turbo Debugger "breakpoint on changed
data" feature - probably one of the most powerful debugging features 
available in TD.

Tom

winfave@dutrun.UUCP (Alexander Verbraeck) (07/23/89)

In article <5984@stiatl.UUCP> tom@stiatl.UUCP (Tom Wiencko) writes:
>> ...
>Likely what has happened is that you are wiping out these memory locations
>with some other modification of a typed constant.  A typed constant is 
>not really much more than an initialized data area, and does not have any
>size or count restrictions that I have ever read about or run into (and
 ^^^^^^^^^^^^^^^^^^^^^^^^^^
>I have some programs with lots and lots of typed constants).
>
>Tom

Except of course for the general restriction of 64 kb per structure!
I would define a typed constant as a variable with an initial value. At
least, that is what I am using it for normally.

---------------------------------------------------------------------
Alexander Verbraeck                            e-mail:
Delft University of Technology                 winfave@hdetud1.bitnet
Department of Information Systems              winfave@dutrun.uucp
PO Box 356, 2600 AJ  The Netherlands
---------------------------------------------------------------------