home *** CD-ROM | disk | FTP | other *** search
- // ex02009.cpp
- // Linkage-specifications
- #include <iostream.h>
- #include <stdlib.h>
- #include <string.h>
-
- // ------ prototype for a C function
- extern "C" int comp(const void *a, const void *b);
-
- main()
- {
- // --------- array of string pointers to be sorted
- static char *brothers[] = {
- "Frederick William",
- "Joseph Jensen",
- "Harry Alan",
- "Walter Elsworth",
- "Julian Paul"
- };
- // ---------- sort the pointers
- qsort(brothers, 5, sizeof(char *), comp);
- // ---------- display the brothers in sorted order
- for (int i = 0; i < 5; i++)
- cout << '\n' << brothers[i];
- }
-
- // ---------- a function compiled with C linkage
- extern "C" {
- int comp(const void *a, const void *b)
- {
- return strcmp(*(char **)a, *(char **)b);
- }
- }