? warning message: ncompatible implicit declaration...

This is a discussion on ? warning message: ncompatible implicit declaration... within the C Programming forums, part of the General Programming Boards category; hi, a program i have compiles fine, but in both OS X 10.4.10 and Fedora 6 i get the following ...

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    2

    ? warning message: ncompatible implicit declaration...

    hi,

    a program i have compiles fine, but in both OS X 10.4.10 and Fedora 6 i get the following warning:

    incompatible implicit declaration of built-in function 'exit'

    the only libraries are <stdio.h> and <string.h>.

    just wondering if anyone has a clue what this might mean. here's an ex. of code that produces the error:
    Code:
    	if (something)			
    	{
    		printf("Blah\n");
    		exit(1);
    	}
    thanks for any help!

    p.s: new to C, coming from perl, ruby & javascript (obviously not compiled :-) )
    Last edited by gluis; 07-22-2007 at 10:22 PM.

  2. #2
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    How about including <stdlib.h>, which is where exit is actually prototyped.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  3. #3
    Registered User
    Join Date
    May 2007
    Posts
    58
    you need to include stdlib.

    maybe in some other compiler it included it automaticaly.

  4. #4
    Chinese pâté foxman's Avatar
    Join Date
    Jul 2007
    Location
    Canada
    Posts
    404
    Quote Originally Posted by Govalant View Post
    you need to include stdlib.

    maybe in some other compiler it included it automaticaly.
    In fact you don't "need" to include it (but i don't mean in any way that you shouldn't include it).

    If you do not include it, when your compiler will "compile" your source code, he won't be able to check if the function call you are making have the right argument type (which can lead to runtime errors if there's a need for conversion from a type to another) and enough argument (example, by not including stdlib.h, you could write something like exit(1, 1) and the program will compile fine, only giving you a warning). Also, it'll assume that every function not declared are returning int.

    Not including header files shouldn't lead to compilation error. It could lead to runtime error tough.

    If you don't believe me, try it. Write something silly like
    Code:
    int main()
    {
    	float fl;
    
    	fl = (float) exit(1, 1);
    
    	return 0;
    }
    ...but i couldn't tell what will happen at runtime.
    Last edited by foxman; 07-22-2007 at 08:40 PM.

  5. #5
    Registered User
    Join Date
    Jul 2007
    Posts
    2
    great. the inclusion of stlib worked perfectly.

    thank u everybody; that was very helpful (i.e. learning about other libs).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File Server Help
    By lautarox in forum C Programming
    Replies: 146
    Last Post: 09-24-2008, 07:32 PM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 02:01 AM
  3. Implicit declaration of function
    By soothsayer in forum C Programming
    Replies: 5
    Last Post: 02-28-2006, 02:56 PM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 10:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21