The C compiler also generates this error if you attempt to define a variable below the start of a function (legal in C99 but not earlier) if that variable declaration used a typedef:
my_struct foo* = func_which_returns_my_struct();
The solution is simple: move "my_struct foo*" to the top of the function and simply leave the assignment ("foo = func...").