Turbo-C qsort problem?
Bob Babcock
PEPRBV%CFAAMP.BITNET at husc6.harvard.EDU
Sun Feb 14 19:55:47 AEST 1988
Has anyone had problems with the qsort routine in Turbo-C version 1.5?
I seem to be getting memory corruption on large sorts with the large
memory model. While I could have a subtle bug somewhere, several tests
indicate that Turbo-C/qsort is at fault:
1. The code is being ported from Computer Innovations C86 (CI86)
where it has been running without problems for a long time.
2. The problem goes away if I replace the Turbo-C qsort with one
from CI86 (for which I have source code). The CI86 qsort has
some fixed size arrays which could overflow, but it checks for
this and aborts if it happens. Is the same true for Turbo-C's
qsort?
3. The problem also goes away if I recompile everything with MSC 5.0
and use the MSC libraries.
Simple test cases seem to work fine, and it is not the list which is
being sorted which gets corrupted, but rather other variables. One
obvious possibility is stack overflow. Telling the linker to use more
stack space didn't help, but the startup code probably sets up the
stack anyway. Turning on stack checking in the routine which calls
qsort did not generate any runtime error messages; I do not have the
Turbo-C sources, so I can't turn on stack checking in qsort itself. My
application is not particularly stack greedy, but I don't know about
the Turbo-C implementation of qsort.
By the way, the CI86 qsort, compiled with either MSC 5.0 or Turbo-C,
seems to be significantly faster than the ones supplied by Borland or
Microsoft.
More information about the Comp.lang.c
mailing list