passing a structure to a routine

I have been programming C for more years than I care to admit and I cannot get this to work under Arduino. The structure works just fine and it compiles and runs. The problem is when I try to pass the structure to a routine I get the error below. It works in other environments.

any ideas?

Thanks
Mark

error: variable or field 'DrawOneBrick' declared void

typedef struct {
int top;
int left;
int bottom;
int right;
int lifeSpan;

} TYPE_Brick;

//*******************************************************************************
void DrawOneBrick((TYPE_Brick)*theBrick)
{

}

Not enough info to see the problem. Never seen someone use parentheses like that in a function declaration.

typedef struct _foo_t { int bar; } foo;

void do_something(foo* f)
{
    f->bar = 5;
}

void loop()
{
    foo F;
    do_something(&f);
}

Try it without the parnentheses around the type
void DrawOneBrick(TYPE_Brick *theBrick)

If that doesn't fix it, perhaps its also falling foul of the Arduino auto-prototyping . Put the function in a separate C file and see if it compiles ok.

My mistake, I was trying lots of different things

This is what it should be and it doesn work either

void DrawOneBrick(TYPE_Brick *theBrick)

"It doesn't work" is not very specific.

Error messages tell you what file and line number it found problems, followed by specific information about the problem.

perhaps its also falling foul of the Arduino auto-prototyping . Put the function in a separate C file and see if it compiles ok.

did you try that?

Thanks for the suggestions, I am trying it but no I cant get a link back to the .pde file

In case anyone is interested, I have written breakout for the SLIDE display. it is working fine but I am trying to pretty it up

#include "Breakout.h"

#ifdef __cplusplus
extern "C"{
#endif

void drawrect( int x1, int y1, int x2, int y2);

#ifdef __cplusplus
} // extern "C"
#endif

#include "Breakout.h"
#include "DrawBricks.h"

//*******************************************************************************
void DrawOneBrick(TYPE_Brick *theBrick)
{
drawrect(theBrick->left, theBrick->top,
kBrickWd, kBrickHt
);

}

gives me

o: In function DrawOneBrick': undefined reference to drawrect'

If that doesn't fix it, perhaps its also falling foul of the Arduino auto-prototyping . Put the function in a separate C file and see if it compiles ok.

Indeed. Arduino's auto-prototyping is not very clever. It puts the prototypes directly after the include-statements, but before any type-definitions. So you need to declare the type in a separate h-file and #include it if you want to use it as a parameter in a function.

halley wrote:

typedef struct _foo_t { int bar; } foo;

void do_something(foo* f)
{
   f->bar = 5;
}

void loop()
{
   foo F;
   do_something(&f);
}

This won't work. When the arduino IDE generates the cpp-file from your project, it will put the prototype for do_something before the tydefef, and compilation will fail.

Thanks, skumlerud. Yet another reason to dislike the "magic" extra parser in the IDE, which gets a lot of declaration stuff wrong. If you change the argument to struct _foo_t* f, it works again.