我指勾不勾选microlib跟memset是否有问题基本无关。我倒认为,勾选了microlib反而会增加出问题的几率。如果代码空间够用,最好别勾选microlib。下面是使用microlib需要注意的一些问题(包括但不限于这些):
Microlib is not compliant with the ISO C library standard. Some ISO features are not supported and others have less functionality.
Microlib is not compliant with the IEEE 754 standard for binary floating-point arithmetic.
Microlib is highly optimized for small code size.
Locales are not configurable. The default C locale is the only one available.
main() must not be declared to take arguments and must not return.
Microlib provides limited support for C99 functions.
Microlib does not support C++.
Microlib does not support operating system functions.
Microlib does not support position-independent code.
Microlib does not provide mutex locks to guard against code that is not thread safe.
Microlib does not support wide characters or multibyte strings.
Microlib does not support selectable one or two region memory models as the standard library (stdlib) does. Microlib provides only the two region memory model with separate stack and heap regions.
Microlib does not support the bit-aligned memory functions _membitcpy[b|h|w][b|l]() and membitmove[b|h|w][b|l]().
Microlib can be used with either --fpmode=std or --fpmode=fast.
The level of ANSI C stdio support that is provided can be controlled with #pragma import(__use_full_stdio).
#pragma import(__use_smaller_memcpy) selects a smaller, but slower, version of memcpy().
setvbuf() and setbuf() always fail because all streams are unbuffered.
feof() and ferror() always return 0 because the error and EOF indicators are not supported.
我指勾不勾选microlib跟memset是否有问题基本无关。我倒认为,勾选了microlib反而会增加出问题的几率。如果代码空间够用,最好别勾选microlib。下面是使用microlib需要注意的一些问题(包括但不限于这些):
Microlib is not compliant with the ISO C library standard. Some ISO features are not supported and others have less functionality.
Microlib is not compliant with the IEEE 754 standard for binary floating-point arithmetic.
Microlib is highly optimized for small code size.
Locales are not configurable. The default C locale is the only one available.
main() must not be declared to take arguments and must not return.
Microlib provides limited support for C99 functions.
Microlib does not support C++.
Microlib does not support operating system functions.
Microlib does not support position-independent code.
Microlib does not provide mutex locks to guard against code that is not thread safe.
Microlib does not support wide characters or multibyte strings.
Microlib does not support selectable one or two region memory models as the standard library (stdlib) does. Microlib provides only the two region memory model with separate stack and heap regions.
Microlib does not support the bit-aligned memory functions _membitcpy[b|h|w][b|l]() and membitmove[b|h|w][b|l]().
Microlib can be used with either --fpmode=std or --fpmode=fast.
The level of ANSI C stdio support that is provided can be controlled with #pragma import(__use_full_stdio).
#pragma import(__use_smaller_memcpy) selects a smaller, but slower, version of memcpy().
setvbuf() and setbuf() always fail because all streams are unbuffered.
feof() and ferror() always return 0 because the error and EOF indicators are not supported.
个人认为,为了保证代码的兼容性、可扩展性、可维护性,只在代码空间实在太大且不违背上述局限性时再考虑使用microlib优化空间的问题。
使用microlib就意味着你要优化。
优化的是代码空间,但优化也意味着损失一些东西,见microlib的一些注意事项。
你使用了相比经过优化的microlib,则意味着附带的优化了自己程序的代码空间。但这些优化是有副作用的(肯定的)。
我认为,这类优化导致了可移植性差(你写的代码在自己的IDE上行,但别人试用时不行了-除非也打开microlib)、扩展性差(因为可能要用RTOS等其它选项,导致你的代码无法添加到这类应用中)等问题。
所以STM32CubeFX中的代码是基于标准c来写的,当然也不会进行任何优化。而优化过的库,比如DSP会进行特殊说明,或者出不同版本(比如优化过的和未优化)的DSP库,以符合各类需求。
我主要是看到很多帖子上来就提勾选microlib,这会导致错误的导向!我认为应该把microlib的问题说清楚,选不选程序员自己决定!
其实,实现起来也没啥难的!
void* memset(void* s, int c, size_t n)
{
unsigned char* p = (unsigned char*) s;
while (n > 0) {
*p++ = (unsigned char) c;
--n;
}
return s;
}
microLib是最大限度的优化代码空间,但貌似处理不好有问题吧