user13373329
user13373329

Reputation:

unused expression when incrementing a pointer

I have a problem, here's the function:

t_coord     cut_input(char **input){
t_coord     coords;

coords.x = ft_atoi(*input);
while (ft_isspace(**input))
    *input++;
while (!ft_isspace(**input))
    *input++;
coords.y = ft_atoi(*input);
while (ft_isspace(**input))
    *input++;
while (!ft_isspace(**input))
    *input++;
return (coords);}

and when I compile it says "error: expression result unused [-Werror,-Wunused-value] *input++;" I dont understand I need to increment this pointer because I call this function multiples times like that

t_coord var1 = cut_input(&input);
t_coord var2 = cut_input(&input);
t_coord var3 = cut_input(&input);
t_coord var4 = cut_input(&input);

so i'm actually using the result so is there anyway I can remove this warning ? I even tried to put a (void)input at the end of the function, didn't work, thank you for your help

Upvotes: 2

Views: 190

Answers (1)

fas
fas

Reputation: 1413

https://en.cppreference.com/w/c/language/operator_precedence

*input++ is equivalent to *(input++), not (*input)++ as you might expect, because postincrement has higher priority than dereference. Since you don't use deferenced value you see unused result error.

  • If you mean increment pointer (get element input points to if input points to an array member for example and make input pointing to the next one) and then dereference use *(input++) or *input++.

  • If you mean dereference and increment value pointer points to use (*input)++.

Upvotes: 3

Related Questions