From: "Stephen Howe" Newsgroups: comp.os.msdos.djgpp Subject: Re: qsort() bug? Or invalid usage??? Date: Fri, 21 Jan 2000 20:06:46 -0000 Organization: UUNET WorldCom server (post doesn't reflect views of UUNET WorldCom Lines: 24 Message-ID: <86ae81$ba3$1@soap.pipex.net> References: <867gpd$k0u$1 AT nets3 DOT rz DOT RWTH-Aachen DOT DE> <388758A7 DOT 1B64BDF9 AT cyberoptics DOT com> <388824A4 DOT 7E8CA268 AT is DOT elta DOT co DOT il> NNTP-Posting-Host: tnagbgate77.tnagb.com X-Trace: soap.pipex.net 948485185 11587 194.202.213.77 (21 Jan 2000 20:06:25 GMT) X-Complaints-To: abuse AT uk DOT uu DOT net NNTP-Posting-Date: 21 Jan 2000 20:06:25 GMT X-Newsreader: Microsoft Outlook Express 4.72.2106.4 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Eli Zaretskii wrote in message <388824A4 DOT 7E8CA268 AT is DOT elta DOT co DOT il>... >AFAIK, ANSI C explicitly allows to access an array one element before the >first one, provided that you don't write there. No it does not, you have it almost right. It allows a pointer value to be one element beyond the end of an array providing you do not write there. It is required behaviour of malloc(). The reason for this is that in a standard for loop you can do for (element *p; p < plast; p++) { } Consider what would happen if p could wrap around the address space. That is why the address of the last byte that malloc returns could never be 0xFFFF or 0xFFFFFFFF. Stephen Howe