Practical way to parse a float with newlib without locale support

随声附和 提交于 2019-12-11 16:48:23

问题


I'm experimenting with NIOS II soft core, trying to minimize the footprint of my embedded app. One of the biggest gains I get comes from using the small C library (p 206):

The full newlib library functionality is often unnecessary for embedded systems, and undesirably large for systems needing a minimal RAM footprint. Altera provides a reduced-functionality reduced-size "Small C" version of newlib which allows smaller RAM footprints to be achieved.

One of the features stripped down from small C library is the locale support. However, when I try to use atof(), the linking fails because it calls localeconv() which is not there. For example, building the following sample

#include <stdlib.h>
int main(void) { return atof("0"); }

results in "/path/to/strtod.c:341: undefined reference to _localeconv_r" error. It's really a shame since the only thing atof() needs is the decimal_point definition.

What options do I have if I need to parse floats, besides including a modified copy of strtod.c in my software? Using regular C library (instead of the small one) increases my code footprint by 35kB which is a big deal for embedded SW.

来源:https://stackoverflow.com/questions/48312018/practical-way-to-parse-a-float-with-newlib-without-locale-support

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!