[SOLVED]Compile error, with pointer to struct?

I have a large program that compiles and works just fine using a makefile outside the IDE.

However on porting it to the IDE (#21) to ensure it's usable by others I get a weird error, I've narrowed the error down to a few lines of code but cannot see the problem.

typedef struct reg {
    unsigned int address;
    char name[8];
    char bits[8][9];
};

void    PrintRegValUsingMask ((reg *)r, byte val) {
}


void    setup() {
}

void    loop() {
}

This produces the following errors with IDE 21

sketch_mar06a:7: error: variable or field 'PrintRegValUsingMask' declared void
sketch_mar06a:7: error: 'r' was not declared in this scope
sketch_mar06a:7: error: expected primary-expression before 'val'

Anyone got an idea what's happening here?


Rob

Yes. The IDE automatically digs through the Sketch, extracts “function prototypes” and stuffs them at the top before sending the file to the compiler. Basically, something similar to this goes to the compiler…

#include <WProgram.h>

void	PrintRegValUsingMask ((reg *)r, byte val);
void	setup();
void	loop();

typedef struct reg {
	unsigned int address;
	char name[8];
	char bits[8][9];
};

void	PrintRegValUsingMask ((reg *)r, byte val) {
}


void	setup() {
}

void	loop() {
}

I think there’s a way to fool the IDE into passing the Sketch without the prototypes but I can’t remember the details. I vaguely recall something about a “#define” as the first line.

The other solution is to move the structure definition into another “tab”; a header file. I know this works and, if you need it, I can provide details.

Thanks Coding Badly, that would explain why the large version of the program gets errors at line 14 which is in the middle of a comment block at the top of the program.

That may also explain why the large version takes about 5 minutes to "compile", I looked at the tasks running and it's java for 4.99 minutes and the compiler for a few seconds. What a crock. It would be realy nice to figure out how to turn that feature off.

The other solution is to move the structure definition into another "tab"; a header file.

I'd like to keep everything in one file, someone on a related thread however has come up with another solution, add "struct"

typedef struct reg {
    unsigned int address;
    char name[8];
    char bits[8][9];
};

void  PrintRegValUsingMask (struct reg * r, byte val) {
}


void  setup() {
}

void  loop() {
}

And that seems to work.

PS, why can't we use highlighting inside a code block any more, we could on the old forum. It makes it impossible to highlight a piece of code.


Rob

PS, why can't we use highlighting inside a code block any more, we could on the old forum. It makes it impossible to highlight a piece of code.

I AGREE! I've resorted to using [ quote ] for small bits of code. That seems to be a reasonable compromise.