//---------------------------------------------------------------- // comb.c // // This file uses recursion to define a function that gives // the number of m-element subsets of an n-element set. It // will be used to illustrate the steps which are needed to // build a Shared Library in the Linux environment. // // compile using: $ gcc -c -fPIC comb.c // // Here the -fPIC option instructs the compiler to generate // Position Independent Code, so that the resulting object- // code can be loaded into memory at an arbitrary address. // // Also, if desired, the resulting object-file 'comb.o' can // be combined with other object-files into a single shared // library, using the command-syntax: // // $ gcc -shared -fPIC -o libcomb.so comb.o other.o // // // REFERENCES: // // Mitchell, Oldham & Samuel, "Advanced Linux Programming" // (New Riders, 2001), pp. 36-43. // // Johnson and Troan, "Linux Application Development" // (Addison-Wesley, 1998), pp. 69-77. // // // programmer: ALLAN CRUSE // written on: 28 JUL 2002 //---------------------------------------------------------------- unsigned int comb( int n, int m ) { if (( n < 0 )||( m < 0 )||( n < m )) return 0; if (( n == 0 )||( m == 0 )||( n == m )) return 1; return comb( n-1, m-1 ) + comb( n-1, m ); }