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; };
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?
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?
Jackson Wright
How can PHP bring me a bunch of women?
Nathan Bailey
They are all traps
Brayden Wright
why are you using pointer to pointer in the first place? you probably dont have to do it, show full code example
Jordan Harris
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.
In my previous implementation that used single pointers, this code was causing segmentation faults, doing it this way fixed the issue.
Colton Moore
>>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.
James Gray
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.
Owen Miller
See:
Jose King
... which seems to be exactly what youre doing
Asher Davis
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
Blake Rodriguez
C is a poorly designed language, all you have left is cope
Charles Hughes
Could you be more specific? I can tell english isn't your first language and I'm having trouble understanding your point.
Bentley Jones
the php ones have to be trannies
Connor Taylor
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.
Luis Collins
What is wrong with this? what does gdb tell you?
Sebastian Fisher
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.
Anthony Richardson
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; }