Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

warning: expression result unused

Tags:

c

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]"?

like image 640
user2840926 Avatar asked Mar 22 '23 03:03

user2840926


1 Answers

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 )));
}
like image 79
Sergey Kalinichenko Avatar answered Apr 01 '23 02:04

Sergey Kalinichenko