struct or typedef

I ran into this problem today trying to define a pointer to the typedef struct inside the very struct I'm defining :

I retreated to struct myStruct syntax as the following:

struct phi_prompt_struct
{
  buffer_pointer ptr;
  four_bytes low; 
  four_bytes high; 
  four_bytes step;
  byte col; 
  byte row; 
  int option; 
  LiquidCrystal *lcd; 
  phi_buttons **btns; 
  DS1307 *RTC; 
  void (*update_function)(phi_prompt_struct *);
}; //26 bytes

See the last line in my struct.

If I did it this way with typedef, the struct is not define as complained by the compiler:

error: 'phi_prompt_struct' has not been declared

Following code used:

typedef struct
{
  buffer_pointer ptr;
  four_bytes low; 
  four_bytes high; 
  four_bytes step;
  byte col; 
  byte row; 
  int option; 
  LiquidCrystal *lcd; 
  phi_buttons **btns; 
  DS1307 *RTC; 
  void (*update_function)(phi_prompt_struct *);
} phi_prompt_struct; //26 bytes

Any remedy some guru can offer so I can use typedef syntax? Thanks!

This compiles:

typedef struct phi_prompt_struct
{
 // blah blah
  byte col; 
  byte row; 
  int option; 
  void (*update_function)(phi_prompt_struct *);
} ; 

void setup () {
  phi_prompt_struct foo;
}

void loop () {}

This

typedef struct phi_prompt_struct
{
  buffer_pointer ptr;
  four_bytes low;
  four_bytes high;
  four_bytes step;
  byte col;
  byte row;
  int option;
  LiquidCrystal *lcd;
  phi_buttons **btns;
  DS1307 *RTC;
  void (*update_function)(struct phi_prompt_struct *);
} phi_prompt_struct; //26 bytes

phi_prompt_struct foo;

or this

typedef struct phi_prompt_struct phi_prompt_struct;

struct phi_prompt_struct
{
  buffer_pointer ptr;
  four_bytes low;
  four_bytes high;
  four_bytes step;
  byte col;
  byte row;
  int option;
  LiquidCrystal *lcd;
  phi_buttons **btns;
  DS1307 *RTC;
  void (*update_function)(phi_prompt_struct *);
} ; //26 bytes

phi_prompt_struct foo;

...should work.

I like the second way because it makes the type of update_function() be the typedef, rather than the identical struct.

Thanks guys. I didn't know I could write the typedef the way you described :slight_smile: I'll consider the second way.