I am trying to pass a pointer by reference to a function and get that function to point my pointer at a structure that it finds.
char get_structure(STRUCTURE **ptr) { if(foundstructure) { *ptr = &theStructure; return 1; } return 0; }
This works how I expect it, but when I try and declare the function prototype in the header file:
char get_structure(STRUCTURE **ptr);
I always get a compiler error:
error C141: syntax error near '*', expected ')'
I don't get an error when this is a defined type like char, int or long, but I get the error when this is a pointer to a typedef that I have defined.
How can I declare this in my header file without an error?
Nathan
I recommend you spend some time with the C language standard. The use of "struct <structname>*" is specifically allowed to be used before the full description of the structure is seen just to avoid problems with circular references.
The thing is that a struct <structname>* is a pointer of known size - as long as you don't try to follow that pointer, you don't need to know how large the struct is, or what member fields it has. If we ignore the issue with specific addressable memory regions in the 8051 processor architecture, or memory models with small/medium/large/huge/... pointers, the size of a pointer to struct is the same what ever the type the struct has. And the word "struct" or "union" before the tag name is enough that the compiler understands that the tag name is the name of a structure or union type. Just seeing "STRUCTURE", the compiler don't know it's one of your own data types. And it's not a known keyword. So the compiler don't know what to do. Your code as written is invalid C code. And the compiler did complain.