Compiling error - Control reaches end of non-void function in C

Viewed 28

When I compile the following snippet of code, I receive the warning message "warning: control reaches end of non-void function"

enum Statetype handleNormalState(int c) {
  if (c == '/'){
    state = slash;
  }
  else if (c == '"') {
    state = charstr;
    putchar(c);
  }
  else if (c == '\'') {
    state = charcon;
    putchar(c);
  }
  else {
    state = normal;
    putchar(c);
  }
}

How can I resolve this?

1 Answers

The most simple way to fix the warning is to modify the function declaration to return void instead of the enum. The warning exists because the compiler made the assumption that you intended to return a value of the type enum Statetype but you forgot to type it in. :)

Related