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
#ifndef __STRUCT_H #define __STRUCT_H #include "function.h" typedef union _STRUCTURE { unsigned char fields[2]; struct _NAMED
Before I forget, one other issue: you need to revisit your naming conventions.
All names starting with two underscores (like __STRUCT_H), and those starting with an underscore followed by an uppercase letter (like _STRUCTURE and _NAMED) are reserved to the implementation. Application code (i.e.: yours) is not supposed to use them.
Bewildering problems like yours can be caused quite easily by violating those rules. People have wasted days of head-scratching trying to figure out what was going on in such cases. E.g. the C compiler has been given explicit licence to predefine _STRUCTURE as the number 7 --- guess you wouldn't like what that would do to your code.
This kind of refactoring isn't possible right now, but rest assured I am aware that this file structure is inadequate. This isn't my project, it's an existing project that someone else created. I am avoiding the use of underscores before defined names now as well. Thanks for both those tips.