What's the most effective way to use double pointers to structs in C?

I've been tinkering around with C because of my data structures course, (which is in Java because fuck me right?), and I've found that often I need to use pointers to pointers to structs. This leads to some messy syntax such as:
[
struct test {
int condition;
};

void useTest(struct test** test_ptr) {
if ((*test)->condition > 0) {
doStuff();
}
}
/code]

Is there a good way to eliminate that syntax? I've tried creating temporary "struct test*" variables inside functions to cope, but that seems pretty undesirable as well. Should I just bite the bullet, or is there a better way?

Attached: 1538961343748.png (673x1068, 579K)

I fucked up my code tags, I meant to have this at the end:
Is there a good way to eliminate that syntax? I've tried creating temporary "struct test*" variables inside functions to cope, but that seems pretty undesirable as well. Should I just bite the bullet, or is there a better way?

How can PHP bring me a bunch of women?

They are all traps

why are you using pointer to pointer in the first place? you probably dont have to do it, show full code example

char create_dstore(DStore** new_dstore, data_t size) {
/**
Creates a new DStore at the provided address with members
of the given size. Returns a non-zero value in case of an
error.

TODO: Implement specific error codes for better debugging
**/
*new_dstore = (DStore*) malloc(sizeof(DStore));
// Verify new_dstore is valid
if (*new_dstore == NULL)
return 1;
**new_dstore = (DStore) {
size,
(DUnit*)malloc(sizeof(DUnit) * size),
(DUnit*)malloc(sizeof(DUnit) * size),
(DUnit*)malloc(sizeof(DUnit) * (ZX+1))
};
DStore* new_dstore_ptr = *new_dstore;
/*
new_dstore->maxsize = size;
new_dstore->memory = (DUnit*)malloc(sizeof(DUnit) * size);
new_dstore->stack = (DUnit*)malloc(sizeof(DUnit) * size);
new_dstore->registry = (DUnit*)malloc(sizeof(DUnit) * (ZX+1));*/
// Verify newly allocated DStore members;
assert(new_dstore_ptr->maxsize == size);
if (new_dstore_ptr->memory == NULL ||
new_dstore_ptr->stack == NULL ||
new_dstore_ptr->registry == NULL)
return 1;
return 0;
}

In my previous implementation that used single pointers, this code was causing segmentation faults, doing it this way fixed the issue.

>>HURR DURR youre only a double star programmer

cant really tell why you need a double pointer from your example.
Ive only ever used it for passing a parameter to a fuction which allocates something for me.

you usually use pointer to pointer when you want to reassign it at some point, as an example when you realloc memory, and no when you actually need to use it you cant substitute it with anything.

See:

... which seems to be exactly what youre doing

also dont create pseudo type links leads to cancer for you, when you will later jump between files header trying to understand what did you wrote down like week before aswell as for others who are trying to understand your code, google article on linux journal website(i dont remember the name) if you want detailed explanation with examples

C is a poorly designed language, all you have left is cope

Could you be more specific? I can tell english isn't your first language and I'm having trouble understanding your point.

the php ones have to be trannies

I think what I'll do is just use the double pointers explicitly, I'm going to need them either way, and obfuscating what I'm doing will doubtlessly confuse me in the long run.

What is wrong with this? what does gdb tell you?

The code I put here is completely functional, the single pointer code was the problem. As for gdb, the issue came from me dereferencing one of the member elements.

That's not a full example, you missed the code that calls the function, so I can't help you much. But here is an example of how you normally do it in c:
char create_dstore(DStore* new_dstore, data_t size) {
*new_dstore = (DStore) {
size,
malloc(sizeof(DUnit) * size),
malloc(sizeof(DUnit) * size),
malloc(sizeof(DUnit) * (ZX+1))
};
return 0;
}

char destroy_dstore(DStore *dstore) {
free(dstore->memory);
free(dstore->stack);
free(dstore->registry);
free(dstore);
}


/* and calling it... */
DStore dstore;
create_dstore(&dstore, 42);

/* cleanup */
destroy_dstore(&dstore);

Is there any specific reason new_store has to be pointer to pointer?

oops, i didn't mean free(dstore) in destroy_dstore function, remove that part

How did you use a single pointer for this? unless you returned it?

Also the functions are usually called "init" and "deinit", which makes more sense here

>C is a poorly designed language
This is the atheism of the programming world, equally lacking in nuance but exuding even more of an obnoxious aura.

use typedef

Look at this retard, look at him and laugh!

*autism

>which is in Java because fuck me right?
its in java precisely because students, like yourself, can't program for shit in C.

That's not an argument my man

Kek retard

Ruby is two trannys

I'll take a python or a C please.
Too much women is deleterious.
Only degenerates maintain a harem

Can you just post the entire code somewhere? Kind of flying blind.

why not just put the function inside the struct?

Yes, you should make a new variable.
void use_test(struct test **test_ptr)
{
struct test *test_; = *test_ptr;
if (test_->condition > 0)
doStuff();
}

So it's an objectively true statement

Absolutely niggerlicious.

Ignore the extra semicolon in the variable definition.