C Language and Libraries Help (clang.hlp) (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
__segment
 Example                                   Up Contents Index Back
─────C/C++ Language─────────────────────────────────────────────────────────
 
  Keyword:   __segment
 
  Syntax:    __segment declarator
 
  Summary:   Data type representing a 16-bit segment address.
 
  See also:  __based, __self
 
     The __segment keyword can be used to provide a segment base for
     based pointers, which are limited to offset values. A based
     pointer is combined with the segment to produce a full address.
     You also can use __segment to specify where data is allocated.
 
     You can declare variables of type __segment:
 
          __segment myseg;
 
     Pointers based on segment variables can be used for dynamic
     allocation of based objects.
     See: Example
 
     Segment variables can be explicitly combined with pointers
     declared as __based( void ) by using the ":>" operator.
 
     You also can use the __segment keyword in cast expressions. The
     segment portion of a pointer's value is extracted by the
     following cast:
 
          (__segment)<ptr>
 
     If <ptr> is a near pointer, the expression evaluates to the
     contents of the DS register. If <ptr> is a far pointer, the
     expression evaluates to the segment portion of <ptr>.
 
     The segment in which a variable resides can also be found with
     a similar cast expression:
 
          (__segment)&<var>
 
     Example
 
          char *chp;
          int i;
 
          // based pointer having same segment value as chp
          char __based( (__segment)chp ) *b_p;
 
          // based pointer using i's segment as its segment value
          double __based( (__segment)&i ) *b_a;
                                    -♦-