Compiling - printf an entry of a two dimensional array works and fails

This code snippet shows the critical parts of my sketch.

The weird thing is: accessMyTriHour compiles fine as it is.
When i have accessMyTriMin without a printf, it compiles fine.
When i have accessMyTriMin with a printf statement, it doesn’t compile. Even when printf is in a called subroutine.

All i get is
Error: Could not compile. Please review your code.

In the RAW output i see at the end (amongst many other lines before)

/usr/local/gcc-arm-embedded/bin/../lib/gcc/arm-none-eabi/5.3.1/../../../../arm-none-eabi/lib/armv7-m/libg_nano.a(lib_a-readr.o): In function `_read_r':
readr.c:(.text._read_r+0x10): undefined reference to `_read'
collect2: error: ld returned 1 exit status
../../../build/module.mk:232: recipe for target 'target/workspace.elf' failed
make[1]: Leaving directory '/firmware/modules/photon/user-part'
make[1]: *** [target/workspace.elf] Error 1
../build/recurse.mk:11: recipe for target 'modules/photon/user-part' failed
make: *** [modules/photon/user-part] Error 2

The code snippet:

void accessTriHour () { 
   // output each array element's value 
   for ( i = 0; i < igregg; i++ ) {
      for ( j = 0; j < hours; j++ ) {
         printf("myTriHour %d, %d = %d \n", i, j, myTriHour[i][j] ); // this line in: compiles.
      }
   }
}

void accessTriMin () { 
   // output each array element's value 
   for ( i = 0; i < igregg; i++ ) {
      for ( j = 0; j < minutes; j++ ) {
          m = myTriMin[i][j] ;
          //printf("m %d, %d = %d \n", i, j, m );  // if commented out: compiles, IF
          blastitout (m);  // having that in: compiler fails. commented this out, too: compiles.
      }
   }
}

void blastitout (int m) {
    h=2;
    printf("a\n" );
}

Any help is highly appreciated.

@mumintroll, there is no “standard output device” for printf() so you need to specify an output stream. Typically, if you want print to the USB serial port, you would use Serial.printf(). On a Photon, for example, you can print to the external UART port (RX/TX pin) using Serial1.printf().

1 Like

Thanks, peekay123!

Runs perfectly through now.

Puzzling that the 1st procedure didn’t throw an error. Anyway. Thanks!

1 Like