Error passing 2-dimensional table to iterate function

I have a demo sketch that includes a status table of XBee radio nodes.
As is, the code runs OK & iterates & prints the table.

But I want to move the iterator code in loop() into the function print_xb_nodes().

If I un-comment the function definition, I get the error:

PrintXBAddress64Array_2.ino:8:21: error: variable or field ‘print_xb_nodes’ declared void
PrintXBAddress64Array_2.ino:8:21: error: ‘xb_node’ was not declared in this scope
PrintXBAddress64Array_2.ino:8:30: error: ‘aXbNode’ was not declared in this scope
PrintXBAddress64Array_2.ino:8:39: error: expected primary-expression before ‘int’

What should the function definition be for print_xb_nodes() ?

// test for passing array of XBee node data to func 
#include <XBee.h>
//#include <Printers.h>

typedef struct {
  XBeeAddress64 AddrDHDL;
  const char NI[20];
  byte status;
} xb_node;

xb_node nodeTable[] = {
{{ 0x0013A200, 0x408DB613 },"REMOTE3",0},
{{ 0x0013A200, 0x4069F1B4 },"REMOTE5",0},
{{ 0x0013A200, 0x40AA39C0 },"FIELD1",0},
{{ 0x0013A200, 0x4098C20D },"FIELD2",0},
{{ 0x00000000, 0x00000000 },"",0}	//NULL end-of-array marker
};

const size_t numberOfNodes = sizeof(nodeTable)/sizeof(nodeTable[0]);

void setup() {
  Serial.begin(57600);
  while (!Serial) {}
}

void loop() {
  
  int j;
  for( int i=1; i<(int)numberOfNodes; i++) {
   Serial.print(i); 
   Serial.print ("\t");
   Serial.print(nodeTable[i].AddrDHDL.getMsb(),HEX);
   Serial.print(" ");
   Serial.print(nodeTable[i].AddrDHDL.getLsb(),HEX);
   Serial.print(" ");
   j=0;
   while(j<20) Serial.print(nodeTable[i].NI[j++]);
   Serial.print(nodeTable[i].status);
   Serial.println();
  }
  
  print_xb_nodes(nodeTable, (int)numberOfNodes);
  while(1);
}

//void print_xb_nodes(xb_node *aXbNode, int row) { }

for( int i=1; i<(int)numberOfNodesWhy not print all of them?

It's only demo code to liiustrate the problem (that I cant define the function to reference the table)

gregc7320:
It's only demo code to liiustrate the problem (that I cant define the function to reference the table)

With the function uncommented the code compiles for me. But then the error messages you posted don't look to match the code that you posted; the line numbers don't look right.

I agree about the line number confusion. The line number references seem to be non-sensical.

You are the 2nd that claims it compiles. The other was on IRC.

Can you run the compiled code & print the table iteration?

gregc7320:
Can you run the compiled code & print the table iteration?

Sure:

1	13A200 4069F1B4 REMOTE50
2	13A200 40AA39C0 FIELD10
3	13A200 4098C20D FIELD20
4	0 0 0

But I did have to tweak the code:

   //while(j<20) Serial.print(nodeTable[i].NI[j++]);
   Serial.print(nodeTable[i].NI);

Since by printing past the end of the visible character string you seem to be getting non-printable characters that make cut-and-paste rather difficult. I’m a little surprised as I thought the rest of the character array would have been default initialised to 0.

That is my next problem to solve. I eventually want to change the NI field from fixed to variable.

But the probem du-jour is why my code (specifically adding a function definition that references the table) errors but does not error for other people.

gregc7320:
But the probem du-jour is why my code (specifically adding a function definition that references the table) errors but does not error for other people.

Do you have any other ino files in the same folder?

I'm a little surprised as I thought the rest of the character array would have been default initialised to 0.

Ah, I see now. There are literal '\0' characters being printed to the serial console. When you cut and paste them into a text editor, the text editor reads that as end of c-string and stops printing. Amusing.

No. FWIW, I'm developing the code on Ubuntu 18.04.1.

Something's fishy if the line numbers don't look right.

Go into your IDE preferences and enable all compiler warnings and verbose compile output.
Recompile and post all the output from the IDE status window.

/usr/share/arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -D__PROG_TYPES_COMPAT__ -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard -I/home/greg/sketchbook/libraries/xbee /tmp/build3843273186328217980.tmp/PrintXBAddress64Array_2.cpp -o /tmp/build3843273186328217980.tmp/PrintXBAddress64Array_2.cpp.o 
PrintXBAddress64Array_2.ino:8:21: error: variable or field ‘print_xb_nodes’ declared void
PrintXBAddress64Array_2.ino:8:21: error: ‘xb_node’ was not declared in this scope
PrintXBAddress64Array_2.ino:8:30: error: ‘aXbNode’ was not declared in this scope
PrintXBAddress64Array_2.ino:8:39: error: expected primary-expression before ‘int’
PrintXBAddress64Array_2.ino:17:1: warning: extended initialiser lists only available with -std=c++11 or -std=gnu++11
PrintXBAddress64Array_2.ino:17:1: warning: extended initialiser lists only available with -std=c++11 or -std=gnu++11
PrintXBAddress64Array_2.ino:17:1: warning: extended initialiser lists only available with -std=c++11 or -std=gnu++11
PrintXBAddress64Array_2.ino:17:1: warning: extended initialiser lists only available with -std=c++11 or -std=gnu++11
PrintXBAddress64Array_2.ino:17:1: warning: extended initialiser lists only available with -std=c++11 or -std=gnu++11

There should be more than that. Click in the IDE status window, Control-A, Control-C and then paste into your post.

If you haven't already, try restarting your IDE to remove any corpses.

Restarted IDE. Same output. The only thing I didn't copy/paste is 10 empty line at the start. While this thread is running, I'm spinning up the IDE+libraries on W10 to see if there is any difference.

Well, it appears as though my Linux IDE is corrupt. I downloaded Arduino IDE onto W10 & installed the arduino-xbee library & it compiles and runs with the function definition installed.

I suspect there could be something going on the the automatic function prototype creation that the IDE performs during the build process - that might cause the line numbering issue.

What is the version of your IDE on Ubuntu? Are there any available updates? Maybe try a remove and reinstall.

Re-installing now...

"...
Removing arduino (2:1.0.5+dfsg2-4.1) ...
Removing arduino-core (2:1.0.5+dfsg2-4.1) ...
Removing libjna-java (4.5.1-1) ...
Removing libjna-jni (4.5.1-1) ...
Removing librxtx-java (2.2pre2+dfsg1-1) ...
..."

No change after re-installation.

When you open the help->about dialog, does it really say version 1.0.5?

Yes, same as dpkg reported when uninstalling.

Just installed arduino+xbee library on Ubuntu 16.04.5 & it behaves just the same as my Ubuntu IDE. That is, same error when I add the function definition.

I see that I installed 1.8.5 on Windows.

Wow, that's really ancient; maybe 2013 by the looks of things. I thought that was a recent version of Ubuntu? Why would it ship with or select that old version?

Download the latest version from the Arduino website and you can probably just install it in your home directory.

Edit: And remove the old version to avoid any confusion.

Well, 1.0.5 is the package that Ubuntu still installs.

The problem has disappeard when I downloaded 1.8.5 tarball & installed it. Thankyou everybody.