Reputation: 9
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
typedef void withdrawPtr(int);
typedef void depositPtr(int);
typedef void accountPtr(int);
typedef void deltaccountPtr();
int balance;
pthread_mutex_t mutex1;
i have actually converted an equivalent c++ code to c code
typedef struct
{
int (*read)();
withdrawPtr *withdraw;
depositPtr *deposit;
accountPtr *account;
deltaccountPtr *deltaccount;
} accountstrct;
void *WithdrawThread(void *param)
{
struct accountstrct* Mystruct = (struct accountstrct*) param;
here i get dereferencing pointer to incomplete type. I am not getting how else shud icall the function withdraw here.?
Mystruct->withdrawPtr=*withdraw ;
Mystruct->withdrawPtr(2);
return 0;
}
Upvotes: 0
Views: 139
Reputation: 1742
You never defined struct accountstrct
. Either define the type as struct accountstrct { };
and reference the type using struct accountstrct
or define the type as typedef struct {} accountstrct;
and reference the type using accountstrct
(not "struct accountscrct").
You currently have defined a type called accountstrct
but you are trying to use a type called struct accountstrct
.
Upvotes: 3
Reputation: 56079
I'm not sure how you got those typedef
s to compile. Put the *
in there and make them proper function pointer definitions. Then take out the *
from the struct
fields. And on the bottom, Mystruct
doesn't have a withdrawPtr
field, you probably mean just withdraw
. Speaking of which, where is the withdraw
it's being set to coming from?
Here's more what it should look like:
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
typedef void (*withdrawPtr)(int);
typedef void (*depositPtr)(int);
typedef void (*accountPtr)(int);
typedef void (*deltaccountPtr)();
int balance;
pthread_mutex_t mutex1;
typedef struct
{
int (*read)();
withdrawPtr withdraw;
depositPtr deposit;
accountPtr account;
deltaccountPtr deltaccount;
} accountstrct;
void *WithdrawThread(void *param)
{
struct accountstrct* Mystruct = (struct accountstrct*) param;
...
Mystruct->withdraw = withdraw;
Mystruct->withdraw(2);
return 0;
}
Upvotes: 0