Passing typedef structs fails?

Is it possible to pass typedef structs as function parameters? I get this error when I try to do so:

sketch_nov19a:3: error: variable or field 'showRGB' declared void
sketch_nov19a:3: error: 'RGB' was not declared in this scope
sketch_nov19a:3: error: 'rgb' was not declared in this scope

Here is my test code:

// A simple struct
typedef struct
{
  unsigned char r;
  unsigned char g;
  unsigned char b;
} RGB;


// Function forward declaration
void showRGB(RGB* rgb);

// Obligatory setup
void setup()
{
  Serial.begin(115200);
  
  RGB rgb;
  rgb.r = 127;
  rgb.g = 63;
  rgb.b = 255;
  
  showRGB(&rgb);
}

// Obligatory loop
void loop()
{
}

// Function to test struct parameter passing
void showRGB(RGB* rgb)
{
}

I am using Mac OS X 10.6.8. The same code compiles using CC.

Ah, the IDE is “helping” you here by modifying your source for you.

This makes it compile:

Take the typedef (these lines) and put them into another file. To do this make a new tab in the IDE (button on top RH corner). I used foo.h, containing:

// A simple struct
typedef struct
{
  unsigned char r;
  unsigned char g;
  unsigned char b;
} RGB;

Now your main code reads:

#include "foo.h"

// Function forward declaration
void showRGB(RGB* rgb);

// Obligatory setup
void setup()
{
  Serial.begin(115200);
  
  RGB rgb;
  rgb.r = 127;
  rgb.g = 63;
  rgb.b = 255;
  
  showRGB(&rgb);
}

// Obligatory loop
void loop()
{
}

// Function to test struct parameter passing
void showRGB(RGB* rgb)
{
}

And, tada! It compiles.

Wow! Sure enough! Splitting the typedef out into a header file works great. That's sort of strange. I am using the Arduino IDE by the way. Thank you for the help!