[avr-libc]: Platzverbrauch von printf/sprintf ?

Gast #1117128
Lesenswert?

>Irgendwo gibt's doch auch ne Linker-Option, um Platz zu sparen...


Auszug aus avr-libc doku
http://www.nongnu.org/avr-libc/user-manual/group__avr__stdio.html

Since the full implementation of all the mentioned features becomes 
fairly large, three different flavours of vfprintf() can be selected 
using linker options. The default vfprintf() implements all the 
mentioned functionality except floating point conversions. A minimized 
version of vfprintf() is available that only implements the very basic 
integer and string conversion facilities, but only the # additional 
option can be specified using conversion flags (these flags are parsed 
correctly from the format specification, but then simply ignored). This 
version can be requested using the following compiler options:
-Wl,-u,vfprintf -lprintf_min

Bei floating point
-Wl,-u,vfprintf -lprintf_flt -lm

900ss
Moderator Persönliche Seite #1117152
Lesenswert?

1
% avr-size avr/lib/avr[35]1/{*printf_*.o,ftoa*}
2
   text    data     bss     dec     hex filename
3
     68       0       0      68      44 avr/lib/avr31/fprintf_p.o
4
     80       0       0      80      50 avr/lib/avr31/printf_p.o
5
    106       0       0     106      6a avr/lib/avr31/snprintf_p.o
6
     78       0       0      78      4e avr/lib/avr31/sprintf_p.o
7
   2098       0       0    2098     832 avr/lib/avr31/vfprintf_flt.o
8
    785       0       0     785     311 avr/lib/avr31/vfprintf_min.o
9
     42       0       0      42      2a avr/lib/avr31/vfprintf_p.o
10
   1078       0       0    1078     436 avr/lib/avr31/vfprintf_std.o
11
     98       0       0      98      62 avr/lib/avr31/vsnprintf_p.o
12
     60       0       0      60      3c avr/lib/avr31/vsprintf_p.o
13
     58       0       0      58      3a avr/lib/avr51/fprintf_p.o
14
     76       0       0      76      4c avr/lib/avr51/printf_p.o
15
     96       0       0      96      60 avr/lib/avr51/snprintf_p.o
16
     70       0       0      70      46 avr/lib/avr51/sprintf_p.o
17
   1856       0       0    1856     740 avr/lib/avr51/vfprintf_flt.o
18
    689       0       0     689     2b1 avr/lib/avr51/vfprintf_min.o
19
     34       0       0      34      22 avr/lib/avr51/vfprintf_p.o
20
    958       0       0     958     3be avr/lib/avr51/vfprintf_std.o
21
     86       0       0      86      56 avr/lib/avr51/vsnprintf_p.o
22
     56       0       0      56      38 avr/lib/avr51/vsprintf_p.o
23
    724       0       0     724     2d4 avr/lib/avr31/ftoa_engine.o
24
    682       0       0     682     2aa avr/lib/avr51/ftoa_engine.o

Die .bss-Angaben müssen dabei nicht korrekt sein.  Da das BSS als
common block organisiert wird, stehen die exakten Angaben dafür
erst nach dem Instanziieren durch den Linker fest.  Der statische
RAM-Verbrauch ist aber minimal, es werden jedoch ein paar (ca. 20
plus die zu rettenden Register) Bytes auf dem Stack benötigt.
Moderator Persönliche Seite #1117878
Lesenswert?

printf_p brauchst du nur für stdout, vfprintf_p wirst du rein gar
nicht benötigen, also vermutlich nur sprintf_p und vfprintf_std.
Weiß ja nicht, ob du eher avr31 oder avr51 brauchst, darum hab
ich sie beide mal genommen.

Falls du mit Q-Format ein 64-bit-Integer meinst, das ist bei
vfprintf leider (noch?) nicht dabei.  Wäre halt auch ein ziemlicher
Klopper.  Schade, dass man diesen umständlichen Weg über
verschiedene Bibliotheken gehen muss.  Wenn man dann N mögliche
Freiheitsgrade hat, explodiert die Anzahl (und die Namensgebung...)
der notwendigen verschiedenen Bibliotheken ziemlich schnell.

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren