Skip to main content
replaced http://cs50.stackexchange.com/ with https://cs50.stackexchange.com/
Source Link

Simply put, your check_prime() function has all of the return statements inside if statements. The compiler believes it is theoretically possible (even if not logically possible - remember, compilers are stupid) that the function could execute without ever hitting a return statement. It treats this as a warning, and the make command says to treat all warnings as errors.

There should be at least one return statement that will execute without having to satisfy a condition, as a catchall return. Generally, if the function is looking to validate that something is true, then the catchall should return false. If returning other types, you'll need to consider what is appropriate.

For more info, How to solve "control may reach end of non void function" errorHow to solve "control may reach end of non void function" error

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

Simply put, your check_prime() function has all of the return statements inside if statements. The compiler believes it is theoretically possible (even if not logically possible - remember, compilers are stupid) that the function could execute without ever hitting a return statement. It treats this as a warning, and the make command says to treat all warnings as errors.

There should be at least one return statement that will execute without having to satisfy a condition, as a catchall return. Generally, if the function is looking to validate that something is true, then the catchall should return false. If returning other types, you'll need to consider what is appropriate.

For more info, How to solve "control may reach end of non void function" error

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

Simply put, your check_prime() function has all of the return statements inside if statements. The compiler believes it is theoretically possible (even if not logically possible - remember, compilers are stupid) that the function could execute without ever hitting a return statement. It treats this as a warning, and the make command says to treat all warnings as errors.

There should be at least one return statement that will execute without having to satisfy a condition, as a catchall return. Generally, if the function is looking to validate that something is true, then the catchall should return false. If returning other types, you'll need to consider what is appropriate.

For more info, How to solve "control may reach end of non void function" error

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

Source Link
Cliff B
  • 69.3k
  • 4
  • 33
  • 56

Simply put, your check_prime() function has all of the return statements inside if statements. The compiler believes it is theoretically possible (even if not logically possible - remember, compilers are stupid) that the function could execute without ever hitting a return statement. It treats this as a warning, and the make command says to treat all warnings as errors.

There should be at least one return statement that will execute without having to satisfy a condition, as a catchall return. Generally, if the function is looking to validate that something is true, then the catchall should return false. If returning other types, you'll need to consider what is appropriate.

For more info, How to solve "control may reach end of non void function" error

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)