(C lang) I have the following two functions to compare strings , like memcmp. Using uint8_t[] and uint16_t[] to store different strings(8 bit strings and wide strings).
static int memcmp16_8(const uint16_t *s1, const uint8_t *s2, int len)
{
int c, i;
for(i = 0; i < len; i++) {
c = s1[i] - s2[i];
if (c != 0) {
return c;
}
}
return 0;
}
static int memcmp16(const uint16_t *s1, const uint16_t *s2, int len)
{
int c, i;
for(i = 0; i < len; i++) {
c = s1[i] - s2[i];
if (c != 0) {
return c;
}
}
return 0;
}
The same code looks bad. But I don't know how to reuse codes without macro.