What Am I Not Seeing Here....

A simple skeleton of a program, yet it gives bizarre errors on compile:

/*--------------------------------------------------------------------------------------
Includes
--------------------------------------------------------------------------------------*/
#include <arduino.h>

/*--------------------------------------------------------------------------------------
Defines
--------------------------------------------------------------------------------------*/
// Wire Node Descriptor
typedef struct
{
	char	*Signal;
	char	*Conn;
	int		ConnPin;
	char	*Color;
	uint8_t IOPin;
} t_CableNode;


/****************************************************************************************
 *	Start of Data
 ***************************************************************************************/
t_CableNode PDBRevECable[] =
{
// 8-Pin PDB Connector
{ "GND3",	"PDB8",		1,	"Black",	A0 },
{ "VCC",	"PDB8",		2,	"Red",		A1 },
{ "GND4",	"PDB8",		3,	"Gray",		A2 },
{ "ENA",	"PDB8",		4,	"Blue",		A3 },
{ "FWD",	"PDB8",		5,	"Yellow",	A4 },
{ "JOG",	"PDB8",		6,	"Orange",	A5 },
{ "LSENSE",	"PDB8",		7,	"Purple",	A6 },
{ "PROBE",	"PDB8",		8,	"Brown",	A7 },
// 2-Pin PCB E-Stop Connector
{ "ESTOP",	"PDB2",		1,	"Green",	A8 },
{ "GND2",	"PDB2",		2,	"White",	A9 },
// 6-Pin BOB VFD Connector
{ "GND1",	"BOB6",		1,	"Black",	0 },
{ "VC",		"BOB6",		2,	"Red",		1 },
{ "GND2",	"BOB6",		3,	"White",	2 },
{ "ENA",	"BOB6",		4,	"Blue",		3 },
{ "ESTOP",	"BOB6",		5,	"Green",	4 },
{ "REV",	"BOB6",		6,	"White",	5 },
// 4-Pin BOB PDB Connector
{ "GND3",	"BOB4",		1,	"Black",	6 },
{ "PROBE",	"BOB4",		2,	"Brown",	7 },
{ "VCC",	"BOB4",		4,	"Red",		8 },
// 3-Wire BOB VFD Harness
{ "REV",	"BOBVFD",	1,	"White",	14 },
{ "VC",		"BOBVFD",	2,	"Red",		15 },
{ "GND1",	"BOBVFD",	3,	"Black",	16 },
// 4-Wire PDB VFD Harness
{ "LSENSE",	"PDBVFD",	1,	"Brown",	18 },
{ "FWD",	"PDBVFD",	2,	"Yellow",	19 },
{ "JOG",	"PDBVFD",	3,	"Orange",	20 },
{ "GND4",	"PDBVFD",	4,	"Black",	21 },
{ NULL, NULL, 0, NULL, 0	}
};


void TestCable(t_CableNode *p)
{
}


void setup()
{
}

void loop()
{
}

If I just change the type of the argument to TestCable to anything other than t_CableNode, all is well....

Note the error it flags is weird:

"PDBCableTester.ino:7:16: error: variable or field 'TestCable' declared void"

variable or field??? Why does it not recognize it as a function?

This is compiled for a Mega, so no problems with memory.

Regards,
Ray L.

The IDE adds a prototype for each function at the top of your code BEFORE your typedef. There is a workaround for this problem but I can't remember what it is!. Try moving your typedef to the very first line above the #define.

Mark

holmes4:
The IDE adds a prototype for each function at the top of your code BEFORE your typedef. There is a workaround for this problem but I can't remember what it is!. Try moving your typedef to the very first line above the #define.

Mark

Moved the typdef to the top of the file, and put my own prototype for TestCable right after it. No change.

I'm assuming this is some bizarre Arduino build artifact, but this one really has me stumped!

Regards,
Ray L.

Move the typedef into a separate .h file and include it. I saw this a while ago - weird problem!

Pete

el_supremo:
Move the typedef into a separate .h file and include it. I saw this a while ago - weird problem!

Pete

OK, that fixed it. But yikes! WTF is that??? I wasted an hour trying to fix it, and got nowhere.

Thanks!

Regards,
Ray L.

/*--------------------------------------------------------------------------------------
Includes
--------------------------------------------------------------------------------------*/
#include <arduino.h>

<Arduino.h> for systems that have case-sensitive filenames.

Tag the structure...

/*--------------------------------------------------------------------------------------
Defines
--------------------------------------------------------------------------------------*/
// Wire Node Descriptor
typedef struct tag_CableNode
{
	char	*Signal;
	char	*Conn;
	int		ConnPin;
	char	*Color;
	uint8_t IOPin;
} t_CableNode;


/****************************************************************************************
 *	Start of Data
 ***************************************************************************************/
t_CableNode PDBRevECable[] =
{
// 8-Pin PDB Connector
{ "GND3",	"PDB8",		1,	"Black",	A0 },
{ "VCC",	"PDB8",		2,	"Red",		A1 },
{ "GND4",	"PDB8",		3,	"Gray",		A2 },
{ "ENA",	"PDB8",		4,	"Blue",		A3 },
{ "FWD",	"PDB8",		5,	"Yellow",	A4 },
{ "JOG",	"PDB8",		6,	"Orange",	A5 },
{ "LSENSE",	"PDB8",		7,	"Purple",	A6 },
{ "PROBE",	"PDB8",		8,	"Brown",	A7 },
// 2-Pin PCB E-Stop Connector
{ "ESTOP",	"PDB2",		1,	"Green",	A8 },
{ "GND2",	"PDB2",		2,	"White",	A9 },
// 6-Pin BOB VFD Connector
{ "GND1",	"BOB6",		1,	"Black",	0 },
{ "VC",		"BOB6",		2,	"Red",		1 },
{ "GND2",	"BOB6",		3,	"White",	2 },
{ "ENA",	"BOB6",		4,	"Blue",		3 },
{ "ESTOP",	"BOB6",		5,	"Green",	4 },
{ "REV",	"BOB6",		6,	"White",	5 },
// 4-Pin BOB PDB Connector
{ "GND3",	"BOB4",		1,	"Black",	6 },
{ "PROBE",	"BOB4",		2,	"Brown",	7 },
{ "VCC",	"BOB4",		4,	"Red",		8 },
// 3-Wire BOB VFD Harness
{ "REV",	"BOBVFD",	1,	"White",	14 },
{ "VC",		"BOBVFD",	2,	"Red",		15 },
{ "GND1",	"BOBVFD",	3,	"Black",	16 },
// 4-Wire PDB VFD Harness
{ "LSENSE",	"PDBVFD",	1,	"Brown",	18 },
{ "FWD",	"PDBVFD",	2,	"Yellow",	19 },
{ "JOG",	"PDBVFD",	3,	"Orange",	20 },
{ "GND4",	"PDBVFD",	4,	"Black",	21 },
{ NULL, NULL, 0, NULL, 0	}
};


//void TestCable(t_CableNode *p)
void TestCable(struct tag_CableNode *p)
{
}


void setup()
{
}

void loop()
{
}

PaulS posted a snippet that is placed at the top of the sketch that alters the prototype placement (resolves this problem). I cannot find it. You may have better luck.

How to avoid the quirks of the IDE sketch file pre-preprocessing

Excellent! Thanks much!

I'm surprised I haven't been bitten by this one before. I've written many thousands of lines of code on Arduino in dozens of projects, many of them quite large.

Regards,
Ray L.

RayLivingston:
I'm surprised I haven't been bitten by this one before. I've written many thousands of lines of code on Arduino in dozens of projects, many of them quite large.

Arduino will put the virtual (non visible) forward declaration of user functions only on top of the sketch file, if you do no forward declaration by yourself.

So the simplest solution would be the sequence:

  1. typedef declararation
  2. forward declaration of your function using typedef parameter
  3. implementation of your function using typedef parameter
typedef struct
{
 char *Signal;
 char *Conn;
 int ConnPin;
 char *Color;
 uint8_t IOPin;
} t_CableNode;

void TestCable(t_CableNode *p); // forward declaration of function using typedef parameter

void TestCable(t_CableNode *p) // implementation of function
{
}

jurs:
Arduino will put the virtual (non visible) forward declaration of user functions only on top of the sketch file, if you do no forward declaration by yourself.

So the simplest solution would be the sequence:

  1. typedef declararation
  2. forward declaration of your function using typedef parameter
  3. implementation of your function using typedef parameter
typedef struct

{
char *Signal;
char *Conn;
int ConnPin;
char *Color;
uint8_t IOPin;
} t_CableNode;

void TestCable(t_CableNode *p); // forward declaration of function using typedef parameter

void TestCable(t_CableNode *p) // implementation of function
{
}

I did exactly that, and it did not work. The typdef was at the very top of the file, before even the #includes. Next was the function prototype. Then the #includes and the rest of the code. I got the exact same errors.

Regards,
Ray L.

RayLivingston:
I did exactly that, and it did not work. The typdef was at the very top of the file, before even the #includes. Next was the function prototype. Then the #includes and the rest of the code. I got the exact same errors.

Which version of the Arduino IDE are you using?

I just tested this demo program with Arduino 1.0.5 (Windows):

/*--------------------------------------------------------------------------------------
Includes
--------------------------------------------------------------------------------------*/
#include <Arduino.h>

/*--------------------------------------------------------------------------------------
Defines
--------------------------------------------------------------------------------------*/
// Wire Node Descriptor
typedef struct
{
	char	*Signal;
	char	*Conn;
	int		ConnPin;
	char	*Color;
	uint8_t IOPin;
} t_CableNode;

t_CableNode PDBRevECable[] =
{
// 8-Pin PDB Connector
{ "GND3",	"PDB8",		1,	"Black",	A0 },
{ "VCC",	"PDB8",		2,	"Red",		A1 },
{ "GND4",	"PDB8",		3,	"Gray",		A2 },
{ "ENA",	"PDB8",		4,	"Blue",		A3 },
{ "FWD",	"PDB8",		5,	"Yellow",	A4 },
{ "JOG",	"PDB8",		6,	"Orange",	A5 },
{ "LSENSE",	"PDB8",		7,	"Purple",	A6 },
{ "PROBE",	"PDB8",		8,	"Brown",	A7 },
// 2-Pin PCB E-Stop Connector
//{ "ESTOP",	"PDB2",		1,	"Green",	A8 }, // commented out for UNO
//{ "GND2",	"PDB2",		2,	"White",	A9 }, // commented out for UNO
// 6-Pin BOB VFD Connector
{ "GND1",	"BOB6",		1,	"Black",	0 },
{ "VC",		"BOB6",		2,	"Red",		1 },
{ "GND2",	"BOB6",		3,	"White",	2 },
{ "ENA",	"BOB6",		4,	"Blue",		3 },
{ "ESTOP",	"BOB6",		5,	"Green",	4 },
{ "REV",	"BOB6",		6,	"White",	5 },
// 4-Pin BOB PDB Connector
{ "GND3",	"BOB4",		1,	"Black",	6 },
{ "PROBE",	"BOB4",		2,	"Brown",	7 },
{ "VCC",	"BOB4",		4,	"Red",		8 },
// 3-Wire BOB VFD Harness
{ "REV",	"BOBVFD",	1,	"White",	14 },
{ "VC",		"BOBVFD",	2,	"Red",		15 },
{ "GND1",	"BOBVFD",	3,	"Black",	16 },
// 4-Wire PDB VFD Harness
{ "LSENSE",	"PDBVFD",	1,	"Brown",	18 },
{ "FWD",	"PDBVFD",	2,	"Yellow",	19 },
{ "JOG",	"PDBVFD",	3,	"Orange",	20 },
{ "GND4",	"PDBVFD",	4,	"Black",	21 },
// { NULL, NULL, 0, NULL, 0	} // nothing? Commented out for the demo
};

#define NUMCABLES (sizeof(PDBRevECable)/sizeof(PDBRevECable[0]))

void TestCable(t_CableNode *p); // forward declaration of function using typedef parameter

void TestCable(t_CableNode *p) // implementation of function
{
  Serial.print(p->Signal);
  Serial.print('\t');
  Serial.print(p->Conn);
  Serial.print('\t');
  Serial.print(p->ConnPin);
  Serial.print('\t');
  Serial.print(p->Color);
  Serial.println();
}


void setup()
{
  Serial.begin(9600);
  for (int i=0; i<NUMCABLES; i++)
    TestCable(&PDBRevECable[i]);
}

void loop()
{
}

Compiles fine.
Works as expected.

I commented out some of your data lines, which uses analogue pins that are not available on an UNO.

I'm using 1.5.6.

Regards,
Ray L.

RayLivingston:
I'm using 1.5.6.

Just did additional tests with Arduino 1.5.7 (Windows).
Compiled for board setting UNO, MEGA, DUE.
Works like a charm.

Perhaps you'd either to go back to version 1.0.5 or upgrade to 1.5.7?

Both are working for me, with the demo sketch I posted above.

Well, that could explain why I hadn't seen this before. I've used 1.05 for 90% of the work I've done, and, until this project, only used 1.5.6 for a very large Due-based project. In the future, I think I'll just avoid the whole issue entirely, by following Nicks suggestions, and leaving the sketch file empty. That is basically what I did (for different reasons) in the Due project.

Regards,
Ray L.

RayLivingston:
Well, that could explain why I hadn't seen this before. I've used 1.05 for 90% of the work I've done, and, until this project, only used 1.5.6 for a very large Due-based project.

I also found an Arduino-Version named 1.5.6-r2 on my harddisk.

The sketch I posted in reply #12 compiles also fine with Arduino 1.5.6-r2 (Windows).