Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C/C++ User's Guide - a segment constant based pointer or object has its segment value based on a http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
A segment constant based pointer or object has its segment value based on a
specific, named segment.  A segment constant based object is specified as:


     [type] __based( __segname( "segment" ) ) object_name;

and a segment constant based pointer is specified as:


     [type] __based( __segname( "segment" ) ) *object-name;

where segment is the name of the segment in which the pointer or object is
based.  As shown above, the segment name is always specified as a string.
 There are three special segment names recognized by the compiler:


     "_CODE"
     "_CONST"
     "_DATA"

The "_CODE" segment is the default code segment.  The "_CONST" segment is
the segment containing constant values.  The "_DATA" segment is the default
data segment.  If the segment name is not one of the three recognized names,
then a segment will be created with that name.  If a segment constant based
object is being defined, then it will be placed in the named segment.  If a
segment constant based pointer is being defined, then it can point at
objects in the named segment.

The following examples illustrate segment constant based pointers and
objects.

Example:

     int __based( __segname( "_CODE" ) )  ival = 3;
     int __based( __segname( "_CODE" ) ) *iptr;

ival is an object that resides in the default code segment.  iptr is an
object that resides in the data segment (the usual place for data objects),
but points at an integer which resides in the default code segment.  iptr is
suitable for pointing at ival.

Example:

     char __based( __segname( "GOODTHINGS" ) ) thing;

thing is an object which resides in the segment GOODTHINGS, which will be
created if it does not already exist.  (The creation of segments is done by
the linker, and is a method of grouping objects and functions.  Nothing is
implicitly created during the execution of the program.)

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson