October 9th, 2003, 12:50 PM
passing a struct to a function driving me crazy
New guy here. I'm having a hell of a time with an error message I keep on getting in my C compiler (VS). It gives me the error
"'test' uses undefined struct 'Transaction'"
test is an object of type Transaction (struct)
My code looks like this
It defines a struct, then passes it to extractor(), which is defined in my .h file and implemented in a seperate .c file
struct Transaction test;
I have tried adding typedef to the struct definition, removing "struct" from the 2nd formal parameter of extractor() and its prototype, placing the struct definition above the function prototype in my .h file, but all to no avail. Here they are:
void extractor(char, struct Transaction); //prototype
void extractor(char strTest, struct Transaction test)
It's been driving me crazy especially since it works ok if I compile everything in a single file. This is really my first program in C and I'd really appreciate any help with it.
Thanks and tc
October 9th, 2003, 01:27 PM
I think you need to move the definition of your struct to mylib.h.
October 9th, 2003, 01:28 PM
I'm guessing that's cuz your struct is defined in your main file, and mylib.c has no idea what this struct is. Try defining the struct Transaction in mylib.h instead.
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne
"I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
October 9th, 2003, 01:47 PM
Just piping in with, I hope, a helpful hint.
In a multi-file project, each C/C++ source file is compiled separately from all the others. Each compilation is a separate run of the compiler and nothing whatsoever is remembered between compilations. That means that everything that source file would need to compile has to be available to it.
That is why a struct declaration that more than one source file would need must be in a header file that those source files can then include.
October 10th, 2003, 02:23 PM
Thanks a lot for the replies. That helped a lot!