Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Mac Programming / June 2006



Tip: Looking for answers? Try searching our database.

Incompatible declaration warning - huh?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
campos.coder@gmail.com - 16 Jun 2006 02:18 GMT
I'm using i686-apple-darwin8-gcc-4.0.1 to compile the following code:

#include <unistd.h>
#include <stdio.h>

int main()
{
 if((write(1, "Here is some data\n", 18)) != 18)
   write(2, "A write error has occured on file descriptor 1\n", 46);

 exit(0);
}

Compiling with:

gcc -o simple_write simple_write.c

Getting:

simple_write.c: In function 'main':
simple_write.c:10: warning: incompatible implicit declaration of
built-in function 'exit'

-Cheers
Christopher J. Henrich - 16 Jun 2006 03:40 GMT
> I'm using i686-apple-darwin8-gcc-4.0.1 to compile the following code:
>
[quoted text clipped - 20 lines]
>
> -Cheers

"Implicit declaration" means, I think, that the compiler did not see an
/explicit/ declaration of 'exit()' and made one up... badly.

I note that you included <unistd.h>, and I presume you meant to draw in
the standard UNIX facilities... like 'exit()'. I think you will do
better if you include <stdlib.h>.

Here is a treasure trove that you question spurred me to find:
<http://www.opengroup.org/pubs/online/7908799/index.html>
The gods of UNIX say:

The <unistd.h> header defines miscellaneous symbolic constants and
types, and declares miscellaneous functions.

stdlib.h - standard library definitions

Signature

Chris Henrich
http://www.mathinteract.com
God just doesn't fit inside a single religion.

matt neuburg - 16 Jun 2006 03:42 GMT
> I'm using i686-apple-darwin8-gcc-4.0.1 to compile the following code:
>
[quoted text clipped - 18 lines]
> simple_write.c:10: warning: incompatible implicit declaration of
> built-in function 'exit'

#include <stdlib.h>

m.

Signature

matt neuburg, phd = matt@tidbits.com, http://www.tidbits.com/matt/
Tiger - http://www.takecontrolbooks.com/tiger-customizing.html
AppleScript - http://www.amazon.com/gp/product/0596102119
Read TidBITS! It's free and smart. http://www.tidbits.com

campos.coder@gmail.com - 16 Jun 2006 04:09 GMT
Thanks folks - that was it.

> > I'm using i686-apple-darwin8-gcc-4.0.1 to compile the following code:
> >
[quoted text clipped - 28 lines]
> AppleScript - http://www.amazon.com/gp/product/0596102119
> Read TidBITS! It's free and smart. http://www.tidbits.com
Sherm Pendley - 16 Jun 2006 15:51 GMT
> I'm using i686-apple-darwin8-gcc-4.0.1 to compile the following code:
>
[quoted text clipped - 18 lines]
> simple_write.c:10: warning: incompatible implicit declaration of
> built-in function 'exit'

Others have already explained this error, but - what's the point of calling
exit(0) on the very last line of main()? If you take that out, your program
will behave in precisely the same way.

sherm--

Signature

Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org

matt neuburg - 16 Jun 2006 16:05 GMT
> > I'm using i686-apple-darwin8-gcc-4.0.1 to compile the following code:
> >
[quoted text clipped - 22 lines]
> exit(0) on the very last line of main()? If you take that out, your program
> will behave in precisely the same way.

Right, I was going to mention that. Isn't return(n) from main() the same
as exit(n)? m.

Signature

matt neuburg, phd = matt@tidbits.com, http://www.tidbits.com/matt/
Tiger - http://www.takecontrolbooks.com/tiger-customizing.html
AppleScript - http://www.amazon.com/gp/product/0596102119
Read TidBITS! It's free and smart. http://www.tidbits.com

Sherm Pendley - 16 Jun 2006 16:39 GMT
>> Others have already explained this error, but - what's the point of calling
>> exit(0) on the very last line of main()? If you take that out, your program
>> will behave in precisely the same way.
>
> Right, I was going to mention that. Isn't return(n) from main() the same
> as exit(n)? m.

Yeah, they're functionally identical when used in main(), so using exit(n)
isn't exactly wrong - it's just rather unusual.

Oh, and I was wrong about one thing - you do need one or the other if you're
compiling with -Wall, to avoid a "control reaches the end of a non-void
function" compile warning.

sherm--

Signature

Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org

Michael Ash - 16 Jun 2006 17:02 GMT
> Others have already explained this error, but - what's the point of calling
> exit(0) on the very last line of main()? If you take that out, your program
> will behave in precisely the same way.

If you take it out *and* replace it with return 0;. Just taking it out
means you'll return whatever was lying around on the stack. (Unless main()
is special in this way, but since the compiler warns you that doesn't seem
likely.)

Signature

Michael Ash
Rogue Amoeba Software

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.