| 6 - prefixed with `cx_vcmp` they are taking the values directly as arguments |
6 - prefixed with `cx_vcmp` they are taking the values directly as arguments |
| 7 - prefixed with `cx_cmp` the signature is designed to be compatible with the `cx_compare_func` function pointer type. |
7 - prefixed with `cx_cmp` the signature is designed to be compatible with the `cx_compare_func` function pointer type. |
| 8 |
8 |
| 9 ## Examples |
9 ## Examples |
| 10 |
10 |
| 11 In the following example we use `cx_cmp_int32` as compare function for a `CxList` of `int32_t` values. |
11 In the following example we use `cx_cmp_int32` as the compare function for a `CxList` of `int32_t` values. |
| 12 |
12 |
| 13 ```C |
13 ```C |
| 14 CxList *list = cxArrayListCreate( |
14 CxList *list = cxArrayListCreate( |
| 15 cxDefaultAllocator, // use the default allocator |
15 cxDefaultAllocator, // use the default allocator |
| 16 sizeof(int32_t), // the size of one element |
16 sizeof(int32_t), // the size of one element |
| 17 256 // reseve space for 256 elements |
17 256 // reseve space for 256 elements |
| 18 ); |
18 ); |
| 19 cxSetCompareFunc(list, cx_cmp_int32); // the compare function for the elements |
19 // set the compare function for the elements |
| |
20 cxSetCompareFunc(list, cx_cmp_int32); |
| 20 ``` |
21 ``` |
| 21 |
22 |
| 22 In the next example we simply want to compare two `double` values with rounding tolerance. |
23 In the next example we simply want to compare two `double` values with rounding tolerance. |
| 23 Note how the use of the `cx_vcmp` flavour makes it unnecessary to store the literal in a variable just to be able to take an address. |
24 Note how the use of the `cx_vcmp` flavor makes it unnecessary to store the literal in a variable just to be able to take an address. |
| 24 ```C |
25 ```C |
| 25 double x = ... |
26 double x = ... |
| 26 |
27 |
| 27 if (0 == cx_vcmp(x, 47.11)) { |
28 if (0 == cx_vcmp(x, 47.11)) { |
| 28 // do something when equal (except tolerance) |
29 // do something when equal (except tolerance) |