Type Alias


Callback function that compares two values. You provide a pointer to this callback in certain Core Foundation sorting functions.


typedef CFComparisonResult (*CFComparatorFunction)(const void *val1, const void *val2, void *context);



The first value to compare.


The second value to compare.


An untyped pointer to the context of the evaluation.

The meaning of this value and its use are defined by each comparator function. This value is usually passed to a sort function, such as CFArraySortValues, which then passes it, unchanged, to the comparator function.

Return Value

A CFComparisonResult value that indicates whether the val1 is equal to, less than, or greater than val2. See CFComparisonResult for a list of possible values.


If you need to sort the elements in a collection using special criteria, you can implement a comparator function with the signature defined by this prototype. You pass a pointer to this function in one of the “sort” functions, such as CFArray's CFArraySortValues.

You can also pass pointers to standard Core Foundation comparator functions such as CFStringCompare and CFDateCompare.