12.3 Symbol Definitions

Each segment definition contains a pointer to an array of pointers to symbol definitions.

All symbol files contain an array of pointers to symbols, sorted by symbol value. The bFlags member in the SEGDEF structure indicates whether the segment has an alphabetic symbol table. To obtain a pointer to the numerically ordered array of symbol-definition pointers, add the pSymDef pointer in the current segment definition to the pointer to the current segment definition, as follows:

aSymPtr = (WORD *)((BYTE *)pSegDef + pSegDef->pSymDef);

In addition, symbol files created by MAPSYM versions 5.0 and later may contain an array of pointers sorted alphabetically by symbol name. This array begins immediately after the numeric array:

aSymPtrAlpha = (WORD *)((BYTE *)pSegDef +
        pSegDef->pSymDef + pSegDef->cSymbols * sizeof(WORD));

To obtain a pointer to each symbol definition, add the offset specified by each element in the array of symbol-definition pointers to the pointer to the current segment definition, as follows:

for (n = 0; n < pSegDef->cSymbols; n++) {
    pSymDef = (SYMDEF *)((BYTE *)pSegDef + aSymPtr[n]);
    .
    .
    /* Use the symbol information here. */
    .
    .
}

The SYMDEF structure for these symbol definitions has the following form:

typedef struct {
    WORD wSymVal;       /* symbol address or constant    */
    BYTE cbSymName;     /* length of symbol name         */
    char achSymName[1]; /* n bytes of symbol-name member */
} SYMDEF;

Following are the members of the SYMDEF structure:

wSymVal

Specifies the address of the symbol or the value of a constant.

cbSymName

Specifies the length of the symbol name.

achSymName

Specifies a variable-length array of characters containing the segment name. The name is not null-terminated.

The wSymVal member in the SYMDEF structure is a doubleword value for 32-bit symbols.