Nios® II Software Developer Handbook

ID 683525
Date 8/28/2023
Public
Document Table of Contents

7.13.5.2. Use the Small newlib C Library

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

The Intel FPGA "Small C" newlib implementation is selected via the -msmallc command line option to nios2-elf-gcc.

When using the GUI interface, you may select the small newlib library though the "Small C" BSP setting.

The following table: Comparison of Nios® II "Small C" and "Normal C" newlib Libraries summarizes the differences between the Nios® II "Normal C" and "Small C" newlib library versions.

You can select the small newlib library through BSP settings.

Table 36.  Comparison of Nios® II "Small C" and "Normal C" newlib Libraries
Limitation Functions Affected

Both Small C and Normal C libraries implement the traditional printf() family of routines. However, in Small C, floating point formatting is not implemented because the %f and %g options are not supported.

asnprintf()
asprintf()
fprintf()
printf()
snprintf()
sprintf()
vasnprintf()
vasprintf()
vprintf()
vsnprintf()
vsprintf()

Both Small C and Normal C libraries implement alternate integer-only printf() functions with no %f and %g support.

The functionality of these functions are identical between Small C and Normal C libraries. Using these can save RAM and make core portable between the Small C and Normal C libraries.

asiprintf()
asniprintf()
fiprintf()
iprintf()
siprintf()
sniprintf()
vasiprintf()
vasniprintf()
viprintf()
vsiprintf()
vsniprintf()

Wide-character functions are implemented in the Normal C but NOT in the Small C library.

These functions are provided ONLY in the Normal C library:
fgetwc()
fgetws()
fputsw()
fputwc()
fvwprintf()
fwide()
fwprintf()
fwscanf()
fwscanf()
getw()
getwc()
getwchar()
putw()
putwc()
putwchar()
swprintf()
ungetwc()
vfwprintf()
vfwscanf()
vswprintf()
vwprintf()
wbuf()
wprintf()
wscanf()
wsetup()

The scanf() family of routines is supported in the Normal C but NOT in the Small C library.

These functions are provided ONLY in the Normal C library:
fiscanf()
fscanf()
fwscanf()
iscanf()
scanf()
siscanf()
sscanf()
swscanf()
vfscanf()
vfwscanf()
viscanf()
vscanf()
vswscanf()
wscanf()

Seeking is supported in the Normal C but NOT in the Small C library.

These functions are provided ONLY in the Normal C library:
fseek()
ftell()

The Small C library has no support for opening or closing FILE *. Only pre-opened stdout, stderr, and stdin are available.

These functions are provided ONLY in the Normal C Library:
fopen()
fclose()
fdopen()
fcloseall()
fileno()

The Small C library implements NO buffering of stdio.h() output routines.

These functions provide no buffering in the Small C library:
fiprintf()
fputc()
fputs()
perror()
putc()
putchar()
puts()
printf()
These functions are provided ONLY in the Normal C Library:
setbuf
setvbuf

The Small C library provides NO stdio.h() input routines.

These functions are provided ONLY in the Normal C library:
fgetc()
fgets()
fgetwc()
fgetws()
fiscanf()
gets()
fread()
fscanf()
fwscanf()
getc()
getchar()
getline()
gets()
getw()
getwchar()
iscanf()
scanf()
sscanf()
swscanf()
vfscanf()
vfwscanf()
viscanf()
vscanf()
vswscanf()
vwscanf()
wscanf()

The Small C library provides NO support for locale.

These functions are provided ONLY in the Normal C library:
setlocale()
localeconv()
Note: These functions are a Nios II extension. GCC does not implement them in the small newlib C library.
Note: The small newlib C library does not support MicroC/OS-II.

For more information about the Intel FPGA "Small C" version of the newlib C library, refer to the newlib documentation installed with the Nios® II EDS. You can get to this location by clicking on the Windows Start menu, and then navigating to Programs > Intel FPGA > Nios® II > Nios® II Documentation. You can also find this information by referring to the "Red Hat newlib C Library Documentation" web page.

Note: The Intel FPGA "Small C" version of the newlib C library differs considerably from the normal C version. The previous table: Comparison of Nios® II "Small C" and "Normal C" newlib Libraries summarizes the differences.