Problem - wm_itoa is not returning actual value

Hi,

I have been scratching my head why wm_itoa is not returning the actual value. This is just a simple conversion.

s32 num;
ascii aa[3];
num = 67;
wm_itoa(num, aa);
adl_atSendResponse(ADL_AT_RSP, aa);

I believe the expected value of aa is 43 (hex), but it is still 67.
Am I missing something?

Thanks.

Hiya,

I believe that wm_itoa() is a macro wrapped around itoa(). As itoa() takes a third argument (the radix) I suspect that the wm_itoa() macro has the radix set to 10.

You can have a look through the header files yourself and see how the macro is constructed. I’ll have a look myself when I get back into the office.

If you want to be sure about the conversion (and you only want octal, hex, or decimal conversions) you are probably better off using wm_sprintf() to build the ascii representation of your number.

Ciao, Dave

Hiya,

I’ve just had a look at the header file (wm_stdio.h, for OS 6.52) and I’ve found that a number of the wm_XXX functions are macros over the standard library equivalents, wm_itoa() is NOT, and is defined as follows:

ascii * wm_itoa                     ( s32 a, ascii *szBuffer );

This could be because itoa() is not a standard function defined by ANSII C and is left to the compiler developers to implement if and when required.

It looks like SiWi have chosen to implement it to only convert with a radix 10. I will note that this is NOT mentioned in the ADL user guide - section 3.2.4.1 (OS 6.52, Standard C Function Set) indicates that wm_itoa() is available, but NOT that it defaults to radix 10.

Looks like you’re going to be better off using wm_sprintf() - or implementing your own version of itoa().

ciao, Dave

Hi Dave,

That was also my hunch that wm_itoa is not using a radix of 16, and yes wm_itoa() is not a macro wrapped around itoa because there is no itoa when I clicked on its reference.
I did use wm_sprintf() before I read your reply. :stuck_out_tongue:

Anyway, thanks for the detailed explanation.

Thanks.