Teensy 3.2 compiler/sscanf question.

jim lee

Well-known member
I have the old text Star Trek game ported to my Teensy handheld. I've been updating libraries and ran into an odd issue. Numbers have been disappearing from my display. After the usual hair pulling and other debugging nonsense I've tracked own the error to compiler Optimization settings.

Teensy 3.2
IDE Teesyduino 1.8.19

I pulled out the section of code that I found the error in. And I was able to pull out a snippet that actually displays the error.

When compiling with choice : Smallest code - It fails.
When compiling with choice : Fast or Faster - It works.

In the code, this line :

if (sscanf(linep, "%lf%n", &aaitem, &i) < 1)

returns false instead of true when compiling Smallest code. And works fine under the other two Fast & Faster that I checked.

Can someone explain what's going on? What did I run into here?

#include <serialStr.h>  // This needs LC_baseTools to be installed from the library manager.

serialStr inCom;

void setup() {


void haveCom(char* newStr) {

   char  linep[40];
   int   i;
   double aaitem;
   if (isdigit(*linep) || *linep == '+' || *linep == '-' || *linep == '.') {   // If its a diget, plus, minus or period.. ( Treat it as a number. )
      if (sscanf(linep, "%lf%n", &aaitem, &i) < 1) {                          // If we can NOT find a double in this mess.. (i gets the count of chars it read.)
         Serial.println("No double!");
      } else {
         Serial.print("Got double! : ");

void loop() { idle(); }


-jim lee
Since the code to format floats is so large, when you select "smallest code" a stub is used so that all the floating point formatting code is discarded.