hi
I have a little problem when using function overloading:
when passing different types of pointers as parametrs, sometimes the one with char* is used instead of the one with short*, sometimes the one with var* is used instead of the one with int*, even if the type of other parameters differ. here are the little examples:
here char* is used instead of short* (originally both bytevalue were char, but it is wrong with char and short too)
void array_fillbytes(char* arrayin, int arraylength, char bytevalue)
{
if (!arrayin) return;
if (arraylength <= 0) return;
memset(arrayin, bytevalue, sizeof(char) * arraylength);
}
void array_fillbytes(short* arrayin, int arraylength, short bytevalue)
{
if (!arrayin) return;
if (arraylength <= 0) return;
memset(arrayin, (char)bytevalue, sizeof(short) * arraylength);
}
it does not work properly even if I add an int or var fake parameters respectively in the end, always the one with var* is used:
void ShowArrayElements(int* inarray, int arraylength, var posx, var posy)
{
if (!inarray) return;
int i;
for (i=0; i<arraylength; ++i)
{
draw_text( str_for_int(NULL, inarray[i]), posx, posy + i*20, COLOR_RED );
}
}
void ShowArrayElements(var* inarray, int arraylength, var posx, var posy)
{
if (!inarray) return;
int i;
for (i=0; i<arraylength; ++i)
{
draw_text( str_for_num(NULL, inarray[i]), posx, posy + i*20, COLOR_GREEN );
}
}
in this case only char* is used instead of the short*, all others are fine:
void array_fill(char* arrayin, int arraylength, char elementvalue);
void array_fill(short* arrayin, int arraylength, short elementvalue);
void array_fill(int* arrayin, int arraylength, int elementvalue);
void array_fill(var* arrayin, int arraylength, var elementvalue);
void array_fill(VECTOR* arrayin, int arraylength, VECTOR* elementvalue);
do I do something totally wrong, or the lite-c compiler is playing with me?
I can make workarounds of course, I just want to get more, more, and more knowledge (or engine bugs)