Forum: Compiler & IDEs gcc-msp430-ti-toolchain-5.01.02.00 und float bei printf..


von Holm T. (Gast)


Lesenswert?

Benutzt Jemand die gcc-msp430 Toolchain von TI auf Linux oder wie ich 
auf FreeBSD? (gcc-6.4.0)

Ich habe derzeit das Problem das ein sprintf(buffer,"%f", 5.2) Nichts 
liefert. Wer die avrlibc kennt weiß, das das so ungewöhnlich nicht ist, 
dafür gibts printf in verschiedenen Ausführungen, mit und ohne 
Floatingpoint Code.

Ich habe aber zum gcc-msp430-ti nichts finden können um da dran zu 
drehen, ich weiß das das Problem an der Konfiguration von newlib im 
Paket liegt und nicht am gcc selbst, habe solche Toolchains für andere 
Prozessoren schon selbst gebaut. Ich habe allerdings gelesen das der 
msp430-gcc (das ist ne andere Baustelle) kein float in printf 
unterstützt.

Kennt sich hier Jemand aus und kann konkret dazu etwas berichten?
Was ich nicht wissen will ist, das ich keinen Floating Support auf 
msp430 brauche und man das platzsparender mit Integer Arithmetik auch 
machen kann, ich weiß bereits was geht und bekomme von TI kein Geld 
zurück wenn ich vorhanden Speicher nicht nutze..


Gruß,

Holm

von Walter K. (walter_k488)


Lesenswert?


von Holm T. (Gast)


Lesenswert?

Walter K. schrieb:
> Schau mal:
>
> 
https://stackoverflow.com/questions/23191203/convert-float-to-string-without-sprintf

..ja..derartiges treibt sich auch schon be mir auf der Platte herum, 
danke, aber mich hatte interessiert was genau da los ist und ich habe es 
auch gefunden:

Die newlib wird konfiguriert u.A. mit dem Schalter 
--enable-newlib-nano-formatted-io. In der in newlib/README ist dazu 
Folgendes zu lesen:
1
--enable-newlib-nano-formatted-io'
2
     This builds NEWLIB with a special implementation of formatted I/O
3
     functions, designed to lower the size of application on small systems
4
     with size constraint issues.  This option does not affect wide-char
5
     formatted I/O functions.  Some notes about the feature:
6
      1) The non-wide-char formatted I/O functions only support the C89
7
         standard.  The only exception is the configuration option provides
8
         limited support for long double.  Internally, the nano formatted I/O
9
         functions use double so accuracy is only guaranteed to double
10
         precision.
11
      2) Floating-point support is split out of the formatted I/O code into
12
         weak functions which are not linked by default.  Programs that need
13
         floating-point I/O support must explicitly request linking of one or
14
         both of the floating-point functions: _printf_float or _scanf_float.
15
         This can be done at link time using the -u option which can be passed
16
         to either gcc or ld.  The -u option forces the link to resolve those
17
         function references.  Floating-point format specifiers are recognized
18
         by default, but if the floating-point functions are not explicitly
19
         linked in, this may result in undefined behavior for programs that
20
         need floating-point I/O support.
21
      3) Integer-only versions of the formatted I/O functions (the iprintf/
22
         iscanf family) simply alias their regular counter-parts.
23
         The affected functions are:
24
25
          diprintf vdiprintf
26
27
          siprintf fiprintf iprintf sniprintf asiprintf asniprintf
28
29
          siscanf fiscanf iscanf
30
31
          viprintf vfiprintf vsiprintf vsniprintf vasiprintf vasniprintf
32
33
          viscanf vfiscanf vsiscanf
34
35
          _diprintf_r _vdiprintf_r
36
37
          _siprintf_r _fiprintf_r _iprintf_r _sniprintf_r _asiprintf_r
38
          _asniprintf_r
39
40
          _siscanf_r _fiscanf_r _iscanf_r
41
42
          _viprintf_r _vfiprintf_r _vsiprintf_r _asniprintf_r _vasiprintf_r
43
          _vasniprintf_r
44
45
          _viscanf_r _vfiscanf_r _vsiscanf_r
..ergo habe ich zu den LDFLAGS "-u _printf_float" hinzugefügt und prompt 
funktioniert sprintf wie erwartet.
Ich werde die README mal noch nach anderen Infos abklopfen.

Ich weiß das printf und sprintf "fette Batzen" sind weil sie ziemlich 
viele komplexe Funktionen enthalten, oft benutze ich auch irgendwelche 
tiny-printf Funktionen wie die oben angeführten. Hier aber habe ich 
vorerst Platz und wollte wissen was läuft. Dokumentiert ist das ja eher 
Nirgens...

Gruß,

Holm

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.