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
So maybe:
#ifndef __FUNCTION_H #define __FUNCTION_H void get_struct(union _STRUCTURE **myStruct); #endif
By the way - from the first response you got to your issue: "Have you made sure that STRUCTURE is defined at that point in the header file?"
Thanks very much. This solved the issue. Is there a term used for this type of reference?
Also I'm positive that I was getting no such error in V9.01 when making reference to STRUCTURE except when used in the double pointer scenario.
char get_structure(STRUCTURE *ptr); // == NO ERROR char get_structure(STRUCTURE **ptr); // == ERROR EVERY TIME char get_structure(char **ptr); // == NO ERROR
After the update I could make no reference to STRUCTURE without an error being thrown.
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.