递增指针时未使用表达式结果

时间:2016-06-20 06:27:29

标签: c pointers

当我调用此函数时,即使它们被使用,我也会收到错误。有人可以解释一下:

pointers.c:30:5: warning: expression result unused [-Wunused-value]
    *a++;
    ^~~~

pointers.c:39:9: warning: expression result unused [-Wunused-value]
        *s++;
        ^~~~

pointers.c:40:9: warning: expression result unused [-Wunused-value]
        *b++;
        ^~~~

pointers.c:48:7: warning: expression result unused [-Wunused-value]
      *s++;
      ^~~~
int strend(char *s, char *b){
  char *temp = b; 
  while(*s != '\0'){
    if(*s == *b){
      while(*s == *b && *b != '\0' && *s != '\0'){ 
        *s++;
        *b++;
        if(*b == '\0')
           printf("wrong");
        printf("compare: %c, %c\n", *s, *b);
        printf("equal: %d\n", *s == *b);
      }
    }
    else{
      *s++;
    }
    printf("check %c, %c\n", *s, *b);
    if(*b == '\0' && *s == '\0'){
      return 1;
    }
    else{
      b = temp;
    }
    if(*s == '\0')
      printf("bazinga");
  }
  return 0;
}

1 个答案:

答案 0 :(得分:4)

您也取消引用指针,而不仅仅是递增它。该解除引用将为您提供旧指针所指向的值(在增量之前),但您不会使用该值,从而导致警告。

简单的解决方案?不要使用解除引用运算符*