Problems with "Exit;"

I tried to exit a loop with exit. Like this.

  if (vara>171)
    {
    Dacout0(vara);
    exit;
    }

It did not work. Break works, so there is not a problem but I'm curious. I looked up the word Exit in C++ web references and it is there and there are no errors from compiler either.

use 'break'
'exit' is not part of loops.
http://www.cplusplus.com/reference/clibrary/cstdlib/exit/

There's nowhere to exit to, on a system with no OS.

http://www.cplusplus.com that's where I looked it. But I guess I miss understood it. 'Process/function/loop all the same.' But what does exit do in Arduino or GCC, what assembly code it creates. I wonder why does GCC not know that embedded cpu has no OS to exit. (And give an error.)

I wonder why does GCC not know that embedded cpu has no OS to exit. (And give an error.)

The compiler does not know where the object module it is creating is going to be used.

The linker that creates the hex files from the object modules does not know that the object module contains code derived from the exit() function.

Sometimes, it really is necessary for the programmer to know what is reasonable on the platform they arre developing for.

    exit;

That is not how you call the exit function.

If you called it correctly it would make your program stop executing.

exit() is a unix system call (i.e. a call to the unix kernel, as opposed to a simple library call) that terminates the process that calls it.

The arduino doesn't run unix, or any other oeprating system, so it doesn't know about exit() any more than it knows about fork() , exec(), ioctl(), etc...

-j

LMI_at_work:
(And give an error.)

What error would that be?

The correct function call is:

exit(0);

Which is happily recognised by arduino as it is C++. It produces a very simple pair of instructions:

0000029a <_exit>:
 29a:	f8 94       	cli

0000029c <__stop_program>:
 29c:	ff cf       	rjmp	.-2      	; 0x29c <__stop_program>

which in C++ speak is essentially:

cli(); //prevent interrupts
while(1); //Do nothing forever (or at least until reset)

Thank you all. This was interesting to know