Reputation: 15
I have this header file.
// Bunch of constants defined first
typedef char Token[MAX_TOKEN + 1];
typedef struct
{
Token szToken;
int iCategory;
int iSubcategory;
int iPrecedence;
} Element;
typedef struct
{
int iCount;
Element stackElementM[MAX_STACK_ELEM];
} StackImp;
typedef StackImp *Stack;
typedef struct
{
int iOutCount;
Element outM[MAX_OUT_ITEM];
} OutImp;
typedef OutImp *Out;
// Stack functions
void push(Stack stack, Element value);
Element pop(Stack stack);
int isEmpty(Stack stack);
Stack newStack();
void freeStack(Stack stack);
Element topElement(Stack stack);
void categorize(Element *pElement);
Out newOut();
void addOut(Out out, Element element);
void printOut(Out out);
int convertToPostfix(char *pszInfix, Out out); // This is confusing me...
void ErrExit(int iexitRC, char szFmt[], ...);
char * getToken(char *pszInputTxt, char szToken[], int iTokenSize);
This header is used by a driver which calls int convertToPostfix(char *pszInfix, Out out)
the problem is I keeping getting unknown type name 'Out'
as an error in my compiler. The convertToPostfix function is suppose to take a token indicate if there is any errors, and populate the out array via an addOut function(is in the driver), but I can't do anything because this error is prevent me from compiling! convertToPostfix()
function is NOT part of the driver, it is in a separate C file if this at all matters.
Any help would be great!
EDIT: I first produce an .o file for the driver, then I do the same for the .c file that is convertToPostfix(), it is at this point
COMPILER
gcc -g -c -o myDriver.o myDriver.c //Complies fine.
gcc -g -c -o pretoPost.o pretoPost.c
pretoPost.c:7:38: error: unknown type name ‘Out’
int convertToPostfix(char *pszInfix, Out out)
That I get the error.
EDIT 2: Big thanks to the people to helped! The error was that I didn't include the #include "header.h"
into my pretoPost.c file!
Upvotes: 1
Views: 4692
Reputation: 754030
Transferring comments to an answer.
If Garr Godfrey provides an answer, please accept it — he provided the first pointer to the trouble.
Garr Godfrey [commented]):
"Separate C file" — does that mean it is being compiled, too? Is the header actually being included by the file the error shows up in, because it should be.
Does
pretoPost.c
have#include "mystery.h"
in it (where "mystery.h
" is your unnamed header file)? If not, that's the trouble.
and:
Note that the error message is about
pretoPost.c
not understandingOut
, not about the header not understandingOut
.
And this seems to have been the problem!
Also note that you've not defined a prototype for
newStack()
ornewOut()
in particular. You've declared that the functions exist, but you've not specified the parameter list, so any number and any types of values are allowed. You needOut newOut(void);
andStack newStack(void);
to declare prototypes for the functions. This is C, not C++ — in C++, the rules would be different. (This may just be sloppy coding by your professor if he supplied the header.)
This is a common misunderstanding. A function declaration such as:
void *somefunction();
simply says that somefunction
exists and returns a void *
value. It has no direct specification of the type or number of the arguments, but the function can't be variadic (like printf()
, taking a variable number of arguments) because you must always have a prototype in scope before you use a variadic function. To say 'no arguments', C requires:
void *somefunction(void);
Now you have a prototype. If you compile with GCC, consider:
gcc -std=c11 -Wall -Wextra -Werror -Wmissing-prototypes -Wstrict-prototypes …
It takes a little while to get used to the discipline this imposes, but it ensures you skip testing a lot of bugs.
Upvotes: 4