Re: Functions for coversion strings to intergers

Konstantin Aladyshev

What I meant is there is no difference in the result between the "0"
string, and "hhh" string. Both would get translated to the number
And something like "16dfgdf" would get translated to 16.

But I think I've found a C library function, that is the base for
these StrDecimalToUintnS/StrDecimalToUint64S functions. It is

And in the case of strtol it is a caller responsibility to check for
all the possible error cases via comparing first and second argument:

CHAR16* End;
RETURN_STATUS Status = StrDecimalToUintnS(Argv[Index], &End, &MyVar);
if ((Status != RETURN_SUCCESS) || (Argv[Index] == End) || (*End != 0))
Print(L"Error! incorrect number\n");
So I think that clears my question.
Sorry to bother you.

Best regards,
Konstantin Aladyshev

On Wed, Jul 21, 2021 at 9:23 PM Andrew Fish <afish@...> wrote:

On Jul 21, 2021, at 10:01 AM, Konstantin Aladyshev <aladyshev22@...> wrote:

Are there any library functions that can convert a string with a
decimal number to a number, and tell if the conversion was successful?

What is your definition of successful?

I've found StrDecimalToUintnS and StrDecimalToUint64S functions in a
But it looks like they always return `RETURN_SUCCESS`, no matter if
the passed string contains a number. In this case the function simply
fills the number value with a 0.

Also why aren't there any functions for conversion of signed numbers?
Something like StrDecimalToIntnS/StrDecimalToInt64S ?

Most of the library functions evolved from code duplication in the firmware. Thus we only pick functions that commonly got used.


Andrew Fish

Best regards,
Konstantin Aladyshev

Join to automatically receive all group messages.