tags:

views:

239

answers:

6

Hi All,

I'm fairly new to the C programming language but I know that it is not standardized in the same way as Java.

When performing a comparisson of the runtime of a algorithm, to keep the analysis fair, I need to call a method similar to Java's Array.sort(int []).

void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *));

Seems to be my best bet but I was wondering how I could find out the backend implementation for the version of C that I'm compiling to.

How can I find out which implementation I am using? Does this depend on the Compiler or the includes? I am running I run Ubuntu and use the gcc compiler, all of my tools are obtained through the synaptic package manager or are installed by default.

I hope this question makes sense!

Kind regards,

Gavin

+3  A: 

Hi,

qsort is part of the C stadard library, so a look at the libc code might help: http://www.google.com/codesearch/p?hl=en#XAzRy8oK4zA/libc/stdlib/qsort.c&q=qsort

Hope this helps, Vlad

ddvlad
Fantastic, this is what I was looking for. Knowing the implementation of qsort is taken from Engineering a Sort Function allows me to compare my algorithms with all of the knowledge required.
gav
A: 

qsort is a C standard library function.

Mitch Wheat
+6  A: 

Run

man qsort

It gives the description of what qsort is doing. When you need to find out the information about a C function XXX, try to do man XXX first. Then, if there's not enough info, search for XXX on Google.

Igor Krivokon
Thanks for the tip. The man pages were not installed by default on my machine.In synaptic search for manpages-dev to find the package required.In my muddy question what I was actually seeking was the implementation of quicksort used as this can vary. Pivot choice for example can be implemented in different ways and I don't know enough to be certain the Java and C implementations would be the same.I will certainly use this feature, thank you again.
gav
+2  A: 

I'm fairly new to the C programming language but I know that it is not standardized in the same way as Java.

On the contrary, C is heavily standardised. There has been an ANSI/ISO standard for C since 1989.

anon
If you've looked at the Java spec and the C spec, you'll see the difference. Java's spec is HEAVY by comparison -- not that the C spec is light reading. C spec has a lot of things that are implementation defined. Java has very few.
Dietrich Epp
A: 

What implementation you get depends on the libc you use. But you don't have to care about this too much, they all should behave the same.

cube
+1  A: 

Paul Hsieh present a very fast quicksort in a sorting comparation
Numerical Recipes in C has a excelent quicksort

Lear