printf, floats, and AVR5

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

All right, I'm sure there must be a way to do it, but I'm blowed if I can find it...

Surely there must be a better way of getting floating point printf than including the line

-Wl,-u,vfprintf -lprintf_flt -lm

in the linker miscellaneous column?

I note of course that both libm and libprintf_flt can be included in the linker library section, assuming you know what they are since there's no drop down of available libraries, but I don't see anything which guarantees the -u flag unless it all goes in in one string.

Surely after all this time Atmel would have set things up with a nice friendly button 'do you want to use floating point formatting?'...

Meh.

Neil

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There are three (and a half) ways to go here:

EITHER an IDE has nice and friendly buttons for everything possible, and no provisions for anything but what is catered in this way.

OR it has no nice and friendly buttons at all, giving only lists, and text boxes where you enter the spooky command line stuff

OR it has a little of both

In any case (here's the half) there could be a wizard at project setup, that asked your question, and made the setting.

Quote:
Surely after all this time Atmel would have set things up with a nice friendly button 'do you want to use floating point formatting?'...

Atmel solved the problem of people not understanding why the instruction pointer bounces back and forth when debugging/simulating in C source by making -O0 the default for the debug configuration. Talk about sweeping stuff under the carpet.. With such an approach, how do you expect they will ever come near anything sensible in thie "three-and-a-half-alternative-landscape..?

Could have ben worse.. We could have been talking about FLIP.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Neil,

For AS4 there was a mechanism to pick libprintf_flt.a in a list and automatically have -lprintf_flt added to the link. But it was always the case that you had to manually enter -Wl,-u,vfprintf so if AS5 doesn't have an equivalent it's only half the previous mechanism that is lost - the other half never existed anyway. This is one occasion when an external Makefile generated by Mfile is actually easier to use. You just remove the # from one line and put it on another to switch the printf() support.

PS should I move this to AS5 forum (which the AS5 developers monitor) in the hope they might pick up on this and finally implement the solution that AS4 should have had all along?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Wouldn't hurt, Cliff.

My feeling is that this is something which trips people up pretty regularly, and I think the A5 people are somewhat constrained by the MS Visual IDE... it may be that there *is* a way, but with all respect to Johan, I don't think that the presence of an IDE should require knowledge of, or editing of, an externally generated make file to get this implemented.

As was suggested, either an extra line in the wizard for a new project, or, since one may not know whether it's actually required - I've done without it for seven years on this code - perhaps just a tickbox in, say, the misc section of the Compiler or the Linker section - ideally both, each informing the other.

That makes it simple to add and equally simple to remove again... something along the lines of:

[x] use floating point in printf? (note: automatically includes libm and libprintf_flt)

Just a thought...

Neil

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I presume that

-Wl,-u,vfprintf

simply adds vfprintf to the unresolved symbols list.

I have not tried it, but I would assume that adding

vfprintf((stdout, "");

would have the same effect. The linker pulls in vfprintf() from your specified library. Otherwise it will pull in the default vfprintf() from libc.a.

Since you have a pretty good idea that you will need libprintf_flt.a or libprintf_min.a in at least one of your source files, it is no great penalty.

In fact you could add it to your FDEV macro.

The purists out there will complain that you are wasting 4 or 5 instructions invoking a function that does nothing.

David.