I want to start a linked list with the pointer arguments such as:
/ * * Start a linked list using variadic arguments * Number of initial structures * / int init_structures (structure structure * first, ...) {struct structure * s; Unsigned int count = 0; Va_list va; Va_start (VA, earlier); (S = first; s! = NULL; s = va_arg (va, (struct structure *)) {if ((s = malloc (sizeof (struct structure)) == NULL {perror ("malloc"); exit (EXIT_FAILURE);} calculation ++;} Va_end (va); return calculation;}
The problem is that the clag errors type name is a specification or qualification >, And specify that type to specify the type of int variable it is
. This, which is (structure structure *)
and < It also notes the immediate form at code> struct structure * s
to in (Structure Structure *)
.
(Structure Structure *) , but initially created The structures are inaccessible.
Why is the bracket given to VArade around type arguments int
assumed? How can I fix this?
There is nothing to do with the reasons that your initial structure is "inaccessible" you are allocating the structures and assigning them to and caller should: va_arg
is a macro on many systems, and clearly the struct structure * Do this because of causes.
s
, but S
You can not affect any value in the caller by specifying the local variable. To complete what you want to do, the caller needs to pass the pointer to a pointer, which you can then start
int init_structures (structure structure ** First, ...) {structure structure ** s; Unsigned int count = 0; Va_list va; Va_start (VA, earlier); (S = first; s! = Null; s = va_arg (va, structure structure **)) {if ((* s = malloc (sizeof (struct structure)) == NULL {perror ("malloc"); exit (EXIT_FAILURE);} calculation ++;} Va_end (va); return calculation;}
structure structure * A, * b; Init_structures (& amp; a, & amp; b, NULL);
Comments
Post a Comment