home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c031 / 4.ddi / SAMPLES / CPPTUTOR / LINKAGE.CP$ / LINKAGE
Encoding:
Text File  |  1991-12-12  |  957 b   |  38 lines

  1. // LINKAGE.CPP
  2.  
  3. // This is an example program from Chapter 2 of the C++ Tutorial. This
  4. //     program demonstrates the use of a linkage specification.
  5.  
  6. #include <iostream.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9.  
  10. // ------ Prototype for a C function
  11. extern "C" int comp( const void *a, const void *b );
  12.  
  13. void main()
  14. {
  15.    // --------- Array of string pointers to be sorted
  16.    static char *brothers[] = {
  17.       "Frederick William",
  18.       "Joseph Jensen",
  19.       "Harry Alan",
  20.       "Walter Elsworth",
  21.       "Julian Paul"
  22.    };
  23.    // ---------- Sort the strings in alphabetical order
  24.    qsort( brothers, 5, sizeof(char *), comp );
  25.    // ---------- Display the brothers in sorted order
  26.    for( int i = 0; i < 5; i++ )
  27.       cout << '\n' << brothers[i];
  28. }
  29.  
  30. // ---------- A function compiled with C linkage
  31. extern "C"
  32. {
  33.    int comp( const void *a, const void *b )
  34.    {
  35.       return strcmp( *(char **)a, *(char **)b );
  36.    }
  37. }
  38.