From: "Charles Sandmann" Newsgroups: comp.os.msdos.djgpp Subject: Re: Segments vs Selectors Date: Fri, 26 Sep 1997 23:34:16 Organization: Aspen Technology, Inc. Lines: 12 Message-ID: <342c4678.sandmann@clio.rice.edu> References: Reply-To: sandmann AT clio DOT rice DOT edu NNTP-Posting-Host: dmcap2.dmccorp.com To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk > my program as soon as I dereference a byte above segment limit > (obtained from ___dpmi_get_segment_limit(...)). But this does > not happen! It is only when I dereference 64K *above* the stated > segment limit that my program trashes. What is happening here? You get the limit. You call printf, which internally allocates memory, which calls sbrk, which increases the memory from DPMI and increases the limit 64K. You try to touch the memory, which is now valid after the print. Change the order of your calls. Put a print statement first, then get the limit AFTER the print statement, and try it.