Menu

Dev C++ and C exit function

2011-10-24
2012-09-26
  • nonlinearly

    nonlinearly - 2011-10-24

    Hi
    The exit() function is belong to the stdlib.h that is a standard library. Why
    when I use it without include this header the the dev-c++ does not throw any
    error?
    Thanks

     
  • Jim Pattee

    Jim Pattee - 2011-10-25

    What other files have you included?
    stdlib.h could be included in another file.

     
  • nonlinearly

    nonlinearly - 2011-10-28

    Only stdio.h
    But according to the ANSI standard library the exit function belongs to the
    stdlib.h!

     
  • Jim Pattee

    Jim Pattee - 2011-10-29

    Post your source code and the compile log.

     
  • nonlinearly

    nonlinearly - 2011-11-05

    include <stdio.h>

    int main(void)
    {
    exit(0);
    return 0;
    }

     
  • Jim Pattee

    Jim Pattee - 2011-11-06

    You didn't post the compile log.

    When I compile I get::

    devcpp.cpp: In function 'int main()':
    devcpp.cpp:4:8: error: 'exit' was not declared in this scope

     
  • nonlinearly

    nonlinearly - 2011-11-08

    Compiler: Default compiler
    Executing gcc.exe...
    gcc.exe "C:\Users\me\Desktop\Untitled1.c" -o
    "C:\Users\me\Desktop\Untitled1.exe" -g3 -I"C:\Dev-Cpp\include" -L"C:\Dev-
    Cpp\lib" -g3
    Execution terminated
    Compilation successful

     
  • Jim Pattee

    Jim Pattee - 2011-11-08

    You are using the C compiler, gcc, instead of the C++ compiler, g++
    Changing the program extension from .c to .cpp. will use C++ and give the
    error.

    With mingw C, exit is also a built-in function.
    When I compile with a newer version of the gcc compiler I get the warning:

    devcpp.c: In function 'main':
    devcpp.c:4:2: warning: implicit declaration of function 'exit'
    devcpp.c:4:2: warning: incompatible implicit declaration of built-in function
    'exit'

    Including the header file eliminates the warning.

     
  • nonlinearly

    nonlinearly - 2011-11-10

    Thank you....although I have a question about the compatibility of gcc to
    ANSI. Not compatible with ANSI?

     
  • Jim Pattee

    Jim Pattee - 2011-11-10

    The compiler is ANSI compatible.
    All compiler have additions to ANSI and their own way of implementing ANSI
    standards.
    The compilers may be different even though they are all ANSI compliant.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.