Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

function pointers

Name: Anonymous 2010-12-04 21:31

How do they work and what are they useful for?

Name: Anonymous 2010-12-04 21:40

QSORT(3)                                                              Linux Programmer's Manual                                                             QSORT(3)

NAME
       qsort - sorts an array

SYNOPSIS
       #include <stdlib.h>

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

DESCRIPTION

       The qsort() function sorts an array with nmemb elements of size size.  The base argument points to the start of the array.

       The  contents  of  the  array  are sorted in ascending order according to a comparison function pointed to by compar, which is called with two arguments that
       point to the objects being compared.

       The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be  respectively  less  than,
       equal to, or greater than the second.  If two members compare as equal, their order in the sorted array is undefined.

RETURN VALUE
       The qsort() function returns no value.

CONFORMING TO
       SVr4, 4.3BSD, C89, C99.

NOTES
       Library  routines  suitable  for  use as the compar argument include alphasort(3) and versionsort(3).  To compare C strings, the comparison function can call
       strcmp(3), as shown in the example below.

EXAMPLE
       For one example of use, see the example under bsearch(3).

       Another example is the following program, which sorts the strings given in its command-line arguments:

       #include <stdio.h>
       #include <stdlib.h>
       #include <string.h>

       static int
       cmpstringp(const void *p1, const void *p2)
       {
           /* The actual arguments to this function are "pointers to
              pointers to char", but strcmp(3) arguments are "pointers
              to char", hence the following cast plus dereference */

           return strcmp(* (char * const *) p1, * (char * const *) p2);
       }

       int
       main(int argc, char *argv[])
       {
           int j;

           if (argc < 2) {
            fprintf(stderr, "Usage: %s <string>...\n", argv[0]);
            exit(EXIT_FAILURE);
           }

           qsort(&argv[1], argc - 1, sizeof(argv[1]), cmpstringp);

           for (j = 1; j < argc; j++)
               puts(argv[j]);
           exit(EXIT_SUCCESS);
       }

SEE ALSO
       sort(1), alphasort(3), strcmp(3), versionsort(3)

COLOPHON
       This page is part of release 3.24 of the Linux man-pages project.  A description of the project, and information  about  reporting  bugs,  can  be  found  at
       http://www.kernel.org/doc/man-pages/.

                                                                             2009-09-15                                                                     QSORT(3)

Name: Anonymous 2010-12-05 5:54

>>2
[code] for manpages considered harmful.
Use [m] instead.

Name: Anonymous 2010-12-05 7:35

>>2
Whoa dude use an 80x24 terminal please

Name: Anonymous 2010-12-05 9:06

Seri fucking ously, read SICP.
There are answers for this and all your other stupid (worthy of neophyte) questions.

Name: Anonymous 2010-12-05 9:12

>>2
Did you write a troff to bbcode processor?
Because if you did not, putting that much effort into formatting a document manually is extremely unthesussmanitelike.  Remember that the Sussman always stresses on using abstraction to free yourself from routine.

Name: Anonymous 2010-12-05 13:31

>>6
Yes and I intend to use it very often from now on.

Name: Anonymous 2010-12-05 14:55

>>7
I hope it's
1) written in Scheme
2) GPL3

Name: Anonymous 2010-12-05 16:33

>>8
New BSD License or GTFO.

Name: Anonymous 2010-12-14 9:21

>>9
he uses new bsd license

ahuehuehue

Name: Anonymous 2010-12-14 9:37

MSPL is the One True Licence

Name: Anonymous 2010-12-14 9:46

MSPL Soft Public License

Name: Anonymous 2010-12-14 10:07

MSPL Soft Private License

Name: Anonymous 2010-12-14 11:56

MSPL Soft Penis License

Name: Anonymous 2010-12-14 15:22

>>6
why doesn't sicp cover macros?

Name: Anonymous 2010-12-14 15:43

>>1
they can be used to simulate abstract functions within structs for C. Sorta like interfaces with modern oop languages.

Name: Anonymous 2010-12-14 16:05

>>1
Poor man's high order functions.

Name: Anonymous 2010-12-14 16:05

>>18
s/h/her/

Name: Anonymous 2010-12-14 16:23

>>16
Macros are simply a particular example of metalinguistic abstraction, useful so that you don't have to build a whole new interpreter just to make syntactic abstractions in your program.

Name: Anonymous 2010-12-14 16:56

>>19
Poor man's herigher order functions.

Name: Anonymous 2010-12-14 17:02

>>21
No, herigh order functions. It's s///, not s///g.

Don't change these.
Name: Email:
Entire Thread Thread List