user2840926
user2840926

Reputation: 83

warning: expression result unused

char change(const char c){
  (c >= 'A')&&(c <= 'M') ? (c+'N'-'A') : 
((c >= 'N')&&(c <= 'Z') ? (c-('N'-'A')) : 
((c >='a')&&(c <= 'm') ? (c+'n'-'a') :
((c >= 'n')&&(c <= 'z') ? (c-('n'-'a')) : c )));
}

Why I get "warning: expression result unused" and "error: control reaches end of non-void function [-Werror,-Wreturn-type]"?

Upvotes: 4

Views: 35608

Answers (1)

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726849

You get the warning because the expression gets calculated, and then the result is dropped. This is related to the "reaching the end of the function without returning a value" error: adding return in front of the expression will fix both:

char change(const char c) {
    return (c >= 'A') && (c <= 'M') ? 
        (c+'N'-'A') :  ((c >= 'N') && (c <= 'Z') ? 
             (c-('N'-'A')) : ((c >='a') && (c <= 'm') ? 
                 (c+'n'-'a') : ((c >= 'n') && (c <= 'z') ? 
                     (c-('n'-'a')) : c )));
}

Upvotes: 7

Related Questions