I want to return my struct pointer as a void pointer. In this function when I print the noOfTuples I correctly get zero.
typedef void* HashjoinDatabase;
HashjoinDatabase HashjoinAllocateDatabase(unsigned long totalNumberOfEdgesInTheEnd) {
HashjoinDatabase db;
struct database* d = malloc(sizeof(struct database));
if(d == NULL) {
puts("Some kind of malloc() error");
}
d->tuples = malloc(totalNumberOfEdgesInTheEnd * sizeof(struct tuple));
if(d->tuples == NULL) {
puts("Some kind of malloc() error");
}
d->noOfTuples = 0;
db = &d;
printf("Hello %i\n", d->noOfTuples);
return db;
}
However when in main I cast the returned void pointer back to the struct pointer and try to get the same noOfTuples and I get large varying values with each run which I suspect are addresses
int main() {
HashjoinDatabase testDB = HashjoinAllocateDatabase(10);
int no = ((struct database*)testDB)->noOfTuples;
printf("Hello %i", no);
return 0;
}