1

When I compile find, I get this error message

error: control may reach end of non-void function

When I then try to run the program

./find 14

I get this error message

bash: ./find: No such file or directory.

Also, find isn't there in the folder when I run ls in the terminal. Any idea why may this be happening?

1 Answer 1

7

The warning (converted to an error due to the -Werror option to clang on the appliance)

control may reach end of non-void function

Says that you've a function in your program that's declared to return a value, but it's not guaranteed that it will.

For example, foo(), in the following piece of code, is declared to return an int

int foo(void)
{
    if (false)
    {
        return 10;
    }
}

However, you're not explicitly returning anything in case the if condition is not executed as it's the case. And that's what's meant by control may reach the end of non-void function.


Edit: when you get a compilation error, This means that the compilation process was not successful. Thus, you still don't get the executable file that you'll use to run the program (namely find). And that's why when you try to run

./find 14

it tells you that there's no such file. To fix that, you should first fix the previous error, run

make

or

make find

if you no longer get any compilation error, then you're ready to run your program.

6
  • Thanks Kareem, but I'm not concerned with the fact that the find program is gone despite me having run make find, as well as make all. Any idea why I get the No such file or directory error?
    – user1645
    Jul 7, 2014 at 11:39
  • @user1645 I'm sorry, didn't notice the "No such file or directory" error. I just edited my answer!
    – kzidane
    Jul 7, 2014 at 11:47
  • Great thank you!
    – user1645
    Jul 7, 2014 at 13:08
  • @user1645 you may vote the answer up and accept it if it was helpful! Thank you!
    – kzidane
    Jul 7, 2014 at 23:00
  • 1
    Maybe one thing to add here would be that this isn't actually a syntax error, the compiler actually responds with a warning. If you bypass the CS50 appliance's default make file (either by creating a makefile in your project's directory or by simply compiling manually) you will actually get your file to compile, however if control really reaches end of non-void function the function clears the stack and the return is garbage value. The reason this doesn't compile on the appliance is the -Werror flag that tells the compiler to treat warnings as errors.
    – Andrej
    Jul 6, 2015 at 1:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .