home | |||
links |
|
||
developer's mag main page article part 1 part 2 part 3 part 4 part 5 part 6 part 7 part 8 part 9 |
5 - The Nuts and BoltsThe program's C function to sort an array of longs looks like this:int C_Code_Compare(const void *ptrA,const void *ptrB) { // compare two unsigned longs - cast and subtract return *((unsigned long*)ptrA) - *((unsigned long*)ptrB); }And the qsort() call for this is: qsort( m_array, limit, sizeof(m_array[0]), C_Code_Compare );Where 'm_array' is an array of longs, and 'limit' is the number of them The demo's sort routines (called BadSort() and ASM_BadSort(), so there will be no mistaking them for production code) use the same prototype as qsort(), allowing them to be used interchangeably in the demo. The result is three possible calling functions (the third is qsort() itself) calling either of two comparison functions (in ASM or C), for a total of six possible sorts. Making these functions swappable also aided in checking that the function interfaces worked as expected, a real boon for testing. Previous Section Next Section |
||
Copyright © 2001-2006 ebmDevMag.com - Legal Notice |