rt-thread
rt-thread copied to clipboard
[Feature] 是否可以增加一个rt_atoi函数呢
Describe problem solved by the proposed feature
atoi函数用的还是蛮多的 希望增加一个
Describe your preferred solution
No response
Describe possible alternatives
No response
int rt_atoi(const char* s)
{
int n = 0, sign = 1;
if (*s == '-')
{
sign = -1;
s++;
}
else if (*s == '+')
s++;
while (*s >= '0' && *s <= '9') n = n * 10 + (*s++ - '0');
return sign * n;
}
这种纯函数直接用标准库提供的就行,一般不会有问题的。
会引入额外的库 增加flash占用
这种纯函数直接用标准库提供的就行,一般不会有问题的。
感觉有这类需求时,还是使用c库中的比较好,否则 rt_* 类的c库实现会越来越多。
感觉有这类需求时,还是使用c库中的比较好,否则
rt_*类的c库实现会越来越多。
最好有一个列表,哪些使用 c库实现即可, atoi 是其中之一
主要来说是libc中非常有限的函数,内核中用到的函数。
kerrno.c
rt_strerror(rt_err_t error)– convert an error code to its string form.
kstdio.c
rt_snprintf(char *buf, size_t size, const char *fmt, ...)– bounded formatted print.rt_sprintf(char *buf, const char *format, ...)– unbounded formatted print.rt_vsnprintf(char *buf, size_t size, const char *fmt, va_list args)– core formatter; uses the libc version or the implementations inrt_vsnprintf_std.c/rt_vsnprintf_tiny.cdepending on config.rt_vsprintf(char *buf, const char *format, va_list arg_ptr)– varargs helper that usesrt_vsnprintf.
kstring.c
rt_memset(void *s, int c, size_t count)– fill memory with a byte value.rt_memcpy(void *dst, const void *src, size_t count)– copy memory.rt_memmove(void *dest, const void *src, size_t n)– move memory safely over overlaps.rt_memcmp(const void *cs, const void *ct, size_t count)– compare memory blocks.rt_strstr(const char *s1, const char *s2)– find substring.rt_strcasecmp(const char *a, const char *b)– case-insensitive string compare.rt_strncpy(char *dst, const char *src, size_t n)– copy string with length bound.rt_strcpy(char *dst, const char *src)– copy NUL-terminated string.rt_strncmp(const char *cs, const char *ct, size_t count)– compare strings with length bound.rt_strcmp(const char *cs, const char *ct)– compare NUL-terminated strings.rt_strlen(const char *s)– string length.rt_strnlen(const char *s, size_t maxlen)– bounded string length.rt_strdup(const char *s)– duplicate a string (only whenRT_USING_HEAPis enabled).