[comp.lang.pascal] Problem with constants in Turbo Pascal unit

dms@cs.arizona.edu (David Michael Shackelford) (04/07/90)

In article <90096.105600TBC101@psuvm.psu.edu>, TBC101@psuvm.psu.edu (TomShark Collins) writes:
> I'm having a problem with Turbo Pascal 5.5 and it's inclusion of
> constants in my programs.  I have a unit (Fonts) that contains 12
> constants (arrays 4k in size).  When I just have 'Uses Fonts' in one of
> my programs, everything is ok, it doesn't link the fonts.  If I use any
> reference to just one of the fonts, all are included in the compiled
> program.  My questions are 'Why?' and 'How do I get Turbo to not include

Turbo Pascal uses the unit as the minimum size of linked information.  The
only method I can think of to fix your problem is to have a seperate unit
for each font -- really ugly, no?  An alternative method would be to create
a file/files containing your fonts, and load the appropriate one into a 
single array.  The file would have to contain the binary representations.

Dave.  | dms@cs.arizona.edu 

dmurdoch@watstat.waterloo.edu (Duncan Murdoch) (04/07/90)

In article <90096.105600TBC101@psuvm.psu.edu> TBC101@psuvm.psu.edu (TomShark Collins) writes:
>I'm having a problem with Turbo Pascal 5.5 and it's inclusion of
>constants in my programs.  I have a unit (Fonts) that contains 12
>constants (arrays 4k in size).  When I just have 'Uses Fonts' in one of
>my programs, everything is ok, it doesn't link the fonts.  If I use any
>reference to just one of the fonts, all are included in the compiled
>program.  My questions are 'Why?' and 'How do I get Turbo to not include
>fonts not used?'

In TP 5+, if you put typed constants in separate const blocks, the linker
decides individually whether to include them.  If they're in the same block,
they all get included together.  The same rule applies to global variables:  
put them in separate var blocks if not all of them are always needed. 
(This is mentioned under "smart linking" in the reference guide.)

Duncan Murdoch
in separate

YTHNMADD@MTUS5.BITNET (Noel Maddy) (04/08/90)

Tom "Shark" Collins <TBC101@psuvm.psu.edu> writes:

> I'm having a problem with Turbo Pascal 5.5 and it's inclusion of
> constants in my programs.  I have a unit (Fonts) that contains 12
> constants (arrays 4k in size).  When I just have 'Uses Fonts' in one of
> my programs, everything is ok, it doesn't link the fonts.  If I use any
> reference to just one of the fonts, all are included in the compiled
> program.  My questions are 'Why?' and 'How do I get Turbo to not include
> fonts not used?'
>
> --
> Tom "Shark" Collins       Since ICS is comprised of 2 people, my views
> tbc101@psuvm.psu.edu      are the opinion of at least 50% of the company.
In Turbo Pascal 5.0 (and, I would assume, 5.5), unused data is only
removed on a "per declaration section basis."  In other words, if
you declare

   const
      Font1 = ...;
      Font2 = ...;

and use either constant, Turbo will link both.  The way to get around
this is to make each constant a separate declaration section in your
unit:

   const
      Font1 = ...;

   const
      Font2 = ...;

Not very intuitive, but it works!

 -- Noel Maddy                          Bitnet: ythnmadd@mtus5
'Only by counting could humans          Snail: 210 Vivian
 demonstrate their independence                Hancock, MI  49930
 of computers' - THGttG