I have a very basic question.
What is wrong with this call?
int params[2] = {1, 1};
return strcmp95((char*)buffer1, (char*)buffer2, (long)stringLength, ¶ms);
The function is defined like this:
double strcmp95(char *ying, char *yang, long y_length, int *ind_c[])
{...
When I compile in XCode, I get the following warning:
warning: passing argument 4 of 'strcmp95' from incompatible pointer type
Sorry for being imprecise. Here is the function description:
/* Arguments: ying and yang are pointers to the 2 strings to be compared. The strings need not be NUL-terminated strings because the length is passed. y_length is the length of the strings. ind_c is an array that is used to define whether certain options should be activated. A nonzero value indicates the option is deactivated.
The options are: ind_c[0] Increase the probability of a match when the number of matched characters is large. This option allows for a little more tolerance when the strings are large. It is not an appropriate test when comparing fixed length fields such as phone and social security numbers. ind_c[1] All lower case characters are converted to upper case prior to the comparison. Disabling this feature means that the lower
case string "code" will not be recognized as the same as the upper case string "CODE". Also, the adjustment for similar characters section only applies to uppercase characters. The suggested values are all zeros for character strings such as names. */
params is an int [2], which decays to an int * when passed to a function, and functions that take int []s as parameters are really taking int *s behind the scenes. Unfortunately, ¶ms is an int(*)[2], which is closer to an int * than the int ** (same as int *[] in a function parameter) you need.
Your best option is to change your function to:
double strcmp95(char *ying, char *yang, long y_length, int *ind_c)
And assume that the caller willl always pass an int[2]. Or you can explicitly ask for an int(*)[2] - a pointer to an array of 2 ints:
double strcmp95(char *ying, char *yang, long y_length, int (*ind_c)[2])
But this seems unnecessary to guarantee that two ints are passed, and if you need to account for the possibility of more than two ints in the array is unsuitable. A better way is:
double strcmp95(char *ying, char *yang, long y_length, int *ind_c, size_t len)
size_t is an unsigned integer type guaranteed to be able to hold the size of any object or any array index, and in this case the len parameter is the length of your array ((sizeof params / sizeof params[0]) if you want to be fancy/forward thinking, 2 if you don't). That's the safest route.
By the way, your y_length parameter should also be a size_t variable. long is signed, and I'd hate to have to handle a string of -1 length. Even if you use unsigned long, there's no guarantee that long will be sufficient to handle a system's sizes (or, conversely, that an errantly large long value will be too big for your system to handle and cause confusion).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With