CFAN said:
Here is a example of double-type-conversion
char * __cdecl _itoa (
int val,
char *buf,
int radix
)
{
if (radix == 10 && val < 0)
xtoa((unsigned long)val, buf, radix, 1);
else
xtoa((unsigned long)(unsigned int)val, buf, radix, 0);
return buf;
}
and why need this type of conversion
You don't. See if the following answers your question:
#include <stdio.h>
#include <limits.h>
/* mha: Let's first give a prototype for the non-standard function
xtoa */
inline void xtoa(unsigned long, char *, int, int);
/* mha: remove meaningless invasion of implementation namespace __cdecl,
rename similar _itoa */
char *tst_itoa(int val, char *buf, int radix)
{
if (radix == 10 && val < 0)
/* mha: remove useless cast */
xtoa(val, buf, radix, 1);
else
/* mha: remove useless casts */
xtoa(val, buf, radix, 0);
return buf;
}
/* mha: supply the missing non-standard xtoa */
inline void xtoa(unsigned long value, char *buffer, int unused1,
int unused2)
{
sprintf(buffer, "%lu", value);
}
/* mha: to make a complete compilable program: */
int main(void)
{
char buff[BUFSIZ];
unsigned long foo = ULONG_MAX;
tst_itoa(foo, buff, 10);
printf("For foo=%lu, tst_itoa filled buff with \"%s\"\n", foo,
buff);
return 0;
}
[output]
For foo=4294967295, tst_itoa filled buff with "4294967295"