C - void*Ahoj, mam zadanie doplnit header file (implementovat FIFO zasobnik, ktory ma byt univerzalny co sa datoveho typu tyka) a dostal som predpis funkcii typu void* pop_from_queue(queue_t *queue) atd... Viete mi prosim poradit ako sa s tymto pracuje ? napr : mam tam strukturu typedef struct { int end; int size; void *list;} queue_t; a na prikaze bool push_to_queue(queue_t *queue, void *data){ ... queue->list = data; ...};(a mnoho dalsich) mi hadze chybu ze s tym nespravne pracujem Myslím že pri vracani hodnoty stačí pretypovat premennú:return (void*)output; return je asi jediny prikaz kde mi nehadze chybu mi hadze chybu je velmi presny opis daneho problemu a hocikto by dokazal urcit kde je chyba (no ibaze by mal kristalovu gulu) In file included from queue.c:1:./queue.h:20:29: warning: invalid application of 'sizeof' to a void type sm->list = malloc(sm->size*sizeof(void)); ^ ~~~~~~./queue.h:18:2: warning: variable 'sm' is uninitialized when used here sm->end = 0; ^~./queue.h:17:13: note: initialize the variable 'sm' to silence this warning queue_t *sm; ^ = NULL./queue.h:38:13: warning: subscript of a pointer to void is a GNU extension queue->list = data; ~~~~~~~~~~~^./queue.h:38:26: error: incomplete type 'void' is not assignable queue->list = data; ~~~~~~~~~~~~~~~~~~~~~~~ ^./queue.h:53:20: warning: subscript of a pointer to void is a GNU extension help = queue->list; ~~~~~~~~~~~^./queue.h:53:7: error: assigning to 'void *' from incompatible type 'void' help = queue->list; ^ ~~~~~~~~~~~~~~./queue.h:57:15: warning: subscript of a pointer to void is a GNU extension queue->list = queue->list; ~~~~~~~~~~~^./queue.h:57:32: warning: subscript of a pointer to void is a GNU extension queue->list = queue->list; ~~~~~~~~~~~^./queue.h:57:19: error: incomplete type 'void' is not assignable queue->list = queue->list; ~~~~~~~~~~~~~~ ^./queue.h:74:21: warning: subscript of a pointer to void is a GNU extension return queue->list; ~~~~~~~~~~~^./queue.h:74:10: error: returning 'void' from a function with incompatible result type 'void *' return queue->list; ^~~~~~~~~~~~~~~~cely kod ti tu postovat urcite nebudem... napisal som celkom jasne ze potrebujem vysvetlit ako sa pracuje s void* ako s premennou, tak neviem co mas za problem ziadny problem nemam, neviem ako si na to prisiel. ale popis problemu hadze chybu nie je dostatocny absolutne na nic, nie este na najdenie chyby v kode (ktory ani nemam zaujem vidiet) a nie je na urovni akou sa ma vediet programator vyjadrovat ked nieco potrebuje..najdi si na googli ako sa pracuje s void pointrami a potom sa mozes vratit s takymto pristupom ...
C - void*
|