Discussion:
finding source for gcc's qsort
(too old to reply)
Ron Ford
2008-09-09 22:34:22 UTC
Permalink
Hello newsgroup,

I've been using gcc on windows to sort integers:


void qsort1(int v[], int left, int right)
{

int i, last;
void swap(int v[], int i, int j);

if (left >= right)
return;
swap (v, left, (left + right)/2);
last = left;
for (i = left+ 1; i <= right; i++)
if (v[i] < v[left])
swap (v, ++last, i);
swap(v, left, last);
qsort1(v, left, last - 1);
qsort1(v, last + 1, right);

}

void swap(int v[], int i, int j)
{
int temp;

temp = v[i];
v[i] = v[j];
v[j] = temp;
}

int mycmp(const void *a, const void *b) {
return (*(const int *)a < *(const int *)b);
}

#include <stdio.h>
#define size 9

int main(void)
{
int m[size], i;

for (i=0; i < size; ++ i)
{
m[i] = size - i;
printf(" %d \n ", m[i]);
}

qsort1 (m, 0, size - 1);
for (i=0; i < size; ++ i) printf(" %d \n ", m[i]);



// call library qsort
qsort(m, size, sizeof(int), mycmp);
for (i=0; i < size; ++ i) printf(" %d \n ", m[i]);

return 0;
}

// gcc -o sort c6.c


How do I find the source for the library version of qsort?

Thanks and cheers,
--
We must be willing to pay a price for freedom. 4
H. L. Mencken
Ulrich Eckhardt
2008-09-10 06:11:12 UTC
Permalink
Post by Ron Ford
How do I find the source for the library version of qsort?
It's just a wild guess, but you could actually be lucky and get it via the
download link from the GCC's website.

Uli
Bernd Strieder
2008-09-10 10:44:00 UTC
Permalink
Hello,
Post by Ron Ford
How do I find the source for the library version of qsort?
AFAIK that function usually is in the C library which is not part of
gcc. MinGW and cygwin, both based on windows ports of gcc, seem to use
the Microsoft C library with a little compatibility glue. I'm pretty
sure the sources of the Microsoft C library are not publically
available.

Bernd Strieder
Bernd Strieder
2008-09-10 11:01:42 UTC
Permalink
Hello,
Post by Bernd Strieder
Hello,
Post by Ron Ford
How do I find the source for the library version of qsort?
AFAIK that function usually is in the C library which is not part of
gcc. MinGW and cygwin, both based on windows ports of gcc, seem to use
the Microsoft C library with a little compatibility glue. I'm pretty
sure the sources of the Microsoft C library are not publically
available.
I was wrong on the cygwin part. See the cygwin sources. Cygwin seems to
include newlib, there is a file qsort.c.

Bernd Strieder
Paul Pluzhnikov
2008-09-10 14:11:20 UTC
Permalink
Post by Bernd Strieder
I was wrong on the cygwin part. See the cygwin sources. Cygwin seems to
include newlib, there is a file qsort.c.
You were also mistaken on the source availability of Microsoft LIBC:
it is available with at least "Professional" versions of VisualStudio:

$ cd "/cygdrive/f/Program Files/Microsoft Visual Studio 8/VC/crt/src"
$ grep qsort *.c
qsort.c:*qsort.c - quicksort algorithm; qsort() library function for sorting arrays
qsort.c:* To implement the qsort() routine for sorting arrays.
qsort.c:*qsort(base, num, wid, comp) - quicksort function for sorting arrays
qsort.c:void __fileDECL qsort_s (
qsort.c:void __fileDECL qsort (
qsort_s.c:*qsort_s.c - implementation of the quicksort algorithm
qsort_s.c:* To implement the qsort_s() routine for sorting arrays.
qsort_s.c:*qsort_s(base, num, wid, comp, context) - quicksort function for sorting arrays
qsort_s.c:#include "qsort.c"


Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
Ron Ford
2008-09-11 21:17:21 UTC
Permalink
Post by Paul Pluzhnikov
Post by Bernd Strieder
I was wrong on the cygwin part. See the cygwin sources. Cygwin seems to
include newlib, there is a file qsort.c.
$ cd "/cygdrive/f/Program Files/Microsoft Visual Studio 8/VC/crt/src"
$ grep qsort *.c
qsort.c:*qsort.c - quicksort algorithm; qsort() library function for sorting arrays
qsort.c:* To implement the qsort() routine for sorting arrays.
qsort.c:*qsort(base, num, wid, comp) - quicksort function for sorting arrays
qsort.c:void __fileDECL qsort_s (
qsort.c:void __fileDECL qsort (
qsort_s.c:*qsort_s.c - implementation of the quicksort algorithm
qsort_s.c:* To implement the qsort_s() routine for sorting arrays.
qsort_s.c:*qsort_s(base, num, wid, comp, context) - quicksort function for sorting arrays
qsort_s.c:#include "qsort.c"
Cheers,
Thanks all for responses. I've googled for "qsort.c gcc source" and found
intersting things, but I still have no idea what my qsort on gcc windows
has.

Can someone suggest a better search?
--
What men value in this world is not rights but privileges. 7
H. L. Mencken
Loading...