Category : C++ Source Code
Archive   : C_ALL.ZIP
Filename : TI1007.ASC

 
Output of file : TI1007.ASC contained in archive : C_ALL.ZIP







PRODUCT : Borland C++ NUMBER : 1007
VERSION : 3.0
OS : DOS
DATE : August 12, 1992 PAGE : 1/4

TITLE : Forcing String Literals Into Their Own Data Segment




DISCLAIMER
The following example routines have been provided by the
Technical Support staff at Borland International. They are
provided as a courtesy and not as part of a Borland product,
and as such, are provided without the assurance of technical
support or any specific guarantees.

//..................................................................

This document describes a method of forcing string literals to be
in a unique data segment and demonstrates it with a simple
program.

The program declares enough global data to use up DGROUP, and
also a string table that would cause DGROUP to overflow. By
using the described technique, the string table is placed in a
unique segment, and DGROUP is saved from overflowing.

The text of the string table describes the technique.

To test the technique, break this document into the three
modules:

farstrs.c
strtable.c
makefile

Then from the DOS prompt, execute make.exe to build the program
and run farstrs.exe to prove that it works. Examine the map file
to see the proper placement of segment MYSEG, class FAR_DATA, at
the beginning of the declaration of the various data segments.

//========================================================================
// farstrs.c - the main routine to test the string table
//========================================================================
#include

extern unsigned far stringCount; // number of strings in the table
extern char far *far stringTable[]; // far pointer to far data table

char eatMem[ 0xfc00 ]; // eat up space in DGROUP

int main()













PRODUCT : Borland C++ NUMBER : 1007
VERSION : 3.0
OS : DOS
DATE : August 12, 1992 PAGE : 2/4

TITLE : Forcing String Literals Into Their Own Data Segment




{
int i;

for( i=0; i puts( stringTable[i] );

return eatMem[0];
}

//========================================================================
// strtable.c - declares and initializes the string table
//========================================================================
char *stringTable[] = {

"Although the explanation of this technique is detailed and" ,
"a bit lengthy, this is actually one of the easiest methods of" ,
"forcing string literals into a unique data segment." ,
"" ,
"The keys to using this technique successfully are:" ,
" 1. Proper use of the segment naming compiler directives" ,
" 2. Proper external declaration of you data variables" ,
"" ,
"The declaration of the array of strings is a typical declaration." ,
"The external declaration used in other modules must specify the" ,
"data as far, else the code generated will assume the data is" ,
"relative to DGROUP and you will get the wrong segment when" ,
"referencing the string table. For example:" ,
"" ,
" extern far * far stringTable[];" ,
" extern * far stringTable[];" ,
"" ,
"Since you will probably be in the large memory model, the above" ,
"are effectively the same. However, if you are doing mixed memory" ,
"model programming (ie, in the small model), then you must declare" ,
"the pointer as a far pointer, as in the first of the above two" ,
"options." ,
"" ,
"The compiler options to control the data segment are:" ,
" -zRname = Naming, Data segment" ,
" -zTname = Naming, Data class" ,
" -zSname = Naming, Data group" ,
"" ,
"You must all three directives when compiling the module that" ,













PRODUCT : Borland C++ NUMBER : 1007
VERSION : 3.0
OS : DOS
DATE : August 12, 1992 PAGE : 3/4

TITLE : Forcing String Literals Into Their Own Data Segment




"contains your string table. Then use the default values when" ,
"compiling the rest of the modules in your project." ,
"" ,
"The -zR option can specify any segment name you want, but should" ,
"not conflict with any segment names in the startup code." ,
"" ,
"The -zT option should be set to FARDATA. This is a class name" ,
"that is defined in the startup code. Using it will ensure that" ,
"the data segment for your string table is properly placed at the" ,
"end of the other data segment(s). If you do not do this, or" ,
"modify the startup code to define and properly place the class" ,
"name you wish to use, then the segment containing your strings" ,

"will be placed after the stack segment, and your program will" ,
"fail in the startup code." ,
"" ,
"The -zS option may be given with no name specified to indicate" ,
"no group, or may specifiy a group name you choose." ,
"If you have multiple string tables, you can use the group" ,
"directive to gather strings accross modules into one or more" ,
"groups. If you do not use the -zS option, then your string table" ,
"will get grouped into DGROUP, as if you had done none of these" ,
"steps." ,
"" ,
"For example, you would compile the module containing the " ,
"string table with:" ,
"" ,
" bcc -c -ml -zRmySeg -zTFAR_DATA -zS strtable.c" ,
"" ,
"Then compile your other modules with:" ,
"" ,
" bcc -c -ml main.c" ,
"" ,
"And then link it all together with:" ,
"" ,
" tlink /c c0l main strtable,main,, emu mathl cl" ,
};


const unsigned stringCount = sizeof(stringTable) / sizeof(stringTable[0]);

//========================================================================
// makefile - builds farstrs.exe
//========================================================================













PRODUCT : Borland C++ NUMBER : 1007
VERSION : 3.0
OS : DOS
DATE : August 12, 1992 PAGE : 4/4

TITLE : Forcing String Literals Into Their Own Data Segment




farstrs.exe: farstrs.obj strtable.obj
tlink /v/c/s c0l farstrs strtable,farstrs,farstrs,cl

farstrs.obj: farstrs.c
bcc -c -ml -v $?

strtable.obj: strtable.c
bcc -c -ml -v -zRmySeg -zTFAR_DATA -zS $?

# -zRname ³ Naming, Data segment
# -zSname ³ Naming, Data group
# -zTname ³ Naming, Data class

DISCLAIMER: You have the right to use this technical information
subject to the terms of the No-Nonsense License Statement that
you received with the Borland product to which this information
pertains.


































  3 Responses to “Category : C++ Source Code
Archive   : C_ALL.ZIP
Filename : TI1007.ASC

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/