16.16 The SEGMENTS Statement

The SEGMENTS statement defines the attributes of one or more individual segments in the application or DLL. The attributes specified for a specific segment override the defaults set in the CODE and DATA statements (except as noted). The total number of segment definitions cannot exceed the number set using LINK's /SEG option. (The default without /SEG is 128.)

The SEGMENTS keyword marks the beginning of a section of segment definitions. Multiple definitions must be separated by one or more spaces, tabs, or newline characters. The SEGMENTS statement must appear once before the first definition (on the same or preceding line) and can be repeated before each additional definition. SEGMENTS statements can appear more than once in the file.

Syntax

SEGMENTS
[[']]segmentname[[']] [[CLASS 'classname']] [[attributes]]

or

[[']]segmentname[[']] [[CLASS 'classname']] [[OVL:overlaynumber]]

Remarks

Each segment definition begins with segmentname and is optionally enclosed in single or double quotation marks (' or "). The quotation marks are required if segmentname is a reserved word.

The CLASS keyword optionally specifies the class of the segment. Single or double quotation marks (' or ") are required around classname. If you do not use the CLASS argument, the linker assumes that the class is CODE.

The attributes field applies to segmented executable files. This field accepts one or more optional attributes: discard, executeonly, load, movable, readonly, and shared. Each can appear once, in any order. These attributes are described in the next section, “CODE, DATA, and SEGMENTS Attributes.” LINK ignores attributes if OVL is specified.

The OVL keyword tells LINK to create a DOS program that contains overlays. If OVL is used, LINK assumes EXETYPE DOS. An alternate keyword is OVERLAY. The overlaynumber specifies the overlay in which the segment is to be placed. The value 0 represents the root, and positive decimal numbers through 65,535 represent overlays. By default, a segment is assigned to the root. For more information on overlays, see Chapter 15, “Creating Overlaid DOS Programs.”

Example

The following example specifies segments named cseg1, cseg2, and dseg. The first segment is assigned the class mycode; the second is assigned CODE by default. Each segment is given different attributes.

SEGMENTS

cseg1 CLASS 'mycode'

cseg2 EXECUTEONLY PRELOAD

dseg CLASS 'data' LOADONCALL READONLY