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.
Pointers Based on a Nonfixed Segment
                                             Up Contents Index Back
─────C/C++ Language─────────────────────────────────────────────────────────
 
     Pointers based on a nonfixed segment have access to locations in
     any segment simply by changing the value of the base. Changing a
     single segment value causes all pointers based on that segment to
     address new locations. You can also make assignments to the based
     pointers themselves to change their offset values.
 
     Pointers Based on the Segment of Another Pointer
 
     Form of <base>:
 
          (__segment)<ptr>
 
     A based pointer declared this way uses the segment portion of
     <ptr> as its base. If <ptr> is a near pointer, the declared
     pointer uses the DS register as its base. If <ptr> is a far
     pointer, the declared pointer uses the segment value of <ptr> as
     its base. Changing the segment value of <ptr> causes the based
     pointer to address a new location.
 
     For example:
 
          char __far *far_ptr;
          char __based((__segment)far_ptr) *bp;  // *bp takes the same
                                                 // segment as far_ptr
 
     Pointers Based on a Segment Variable
 
     Form of <base>:
 
          <segvar>
 
     A based pointer declared this way uses <segvar> as its base.
     Assigning a new value to <segvar> causes the based pointer to
     address a different location. This type of based pointer can
     be used for dynamic allocation of based objects.
 
     For example:
 
          __segment seg1;
          char __based(seg1) *bp;  // pointer using seg1 as its base
 
     See: Dynamic Allocation Example
 
     Pointers Based on Another Pointer
 
     Form of <base>:
 
          <ptr>
 
     A based pointer declared this way acts as an offset from <ptr>.
     Assigning a new value to <ptr> causes the based pointer to
     address a different location. The 32-bit compiler recognizes this
     form of based addressing.
 
     For example:
 
          char *cp;
          char __based(cp) *bp;    // pointer using ip as its base
 
          cp = (char *)malloc(100);
          bp = 2;
          *bp = 'a';               // equivalent to cp[2] = 'a';
                                    -♦-