Quote:
|
Originally Posted by Mike
OK, so I've solved some problem and caused some more.
Right now my code is...
I'm getting Error [1146] type mismatch in argument 1 when I try to compile. Any ideas?
EDIT: The error is on Func(object_example);
|
Heck, I'm surprised it compiles that far.
Code:
void Func(struct typedef_example *variable);
void Func(struct typedef_example *variable)
{
...
}
typedef struct name_here
{
int x;
} typedef_example;
typedef_example object_example;
object_example.x = 2;
Func(object_example);
The three things in red illustrate the error. (I think.)
- Typedef is used to give a current type a new name. Using typedef here... well, I don't know what it does. (typedef, first Google result)
- The declaration of object_example is made using typedef_example, which is actually an instance of the struct. The blue shows you where you instanciated it. (You can do the same thing with C++ classes, which is why you have to have that ending semicolon.) To actually do this, you should give the struct a name (where the yellow is), then use that.
- And the one which is definetely causing the error... you forgot the ampersand. (Gets the address of the variable, which is what a pointer holds, vs. the way you have it now which is the actual struct.)
That said, it is possible that C supports this odd annonymous struct typedefed thing, but the way I'd do it would be:
Code:
void Func(struct typedef_example *variable);
struct typedef_example
{
int x;
};
void Func(struct typedef_example *variable)
{
...
}
struct typedef_example object_example;
object_example.x = 2;
Func(&object_example);