LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-16-2010, 08:49 PM   #1
kingliang123
LQ Newbie
 
Registered: Oct 2009
Posts: 7

Rep: Reputation: 0
a problem about "incompatible implicit declaration "


/**main.c**/
/**no head file**/
int main()
{
printf("hello\n");
return 0;
}

build,say,warning:incompatible implicit declaration of built-in function ‘printf’



/*main.c*/
#include<stdio.h>
int main()
{
lnux();
return 0;
}

int lnux(void)
{
return 0;
}
build,say,warning: implicit declaration of function ‘lnux’.

printf, lnux, there are both function, and didn't declaration,why build, them, appear different warning?

due to printf is lib function? lnux not
 
Old 01-16-2010, 09:44 PM   #2
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
i assume because printf is not printf(char *) like you passed to it but rather printf(char *, ...)
 
Old 01-16-2010, 11:41 PM   #3
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
you must declare the function prototype first or define the function before main.

Code:
int lnux(...)
{
   ...
}

main() ...
 
Old 01-17-2010, 12:10 AM   #4
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,539

Rep: Reputation: 60
Im quite confused about what you're actually asking. I was going to explain about what konsolebox said, but I dont know if thats what you're asking. If it isnt, you can turn up your warning levels and you will notice that your first example has a similar warning message as the second one.

Code:
jordan@jordan-laptop:~$ gcc test.c
test.c: In function ‘main’:
test.c:3: warning: incompatible implicit declaration of built-in function ‘printf’
Code:
jordan@jordan-laptop:~$ gcc -Wall test.c
test.c: In function ‘main’:
test.c:3: warning: implicit declaration of function ‘printf’
test.c:3: warning: incompatible implicit declaration of built-in function ‘printf’
Because of this, I think you only see that warning message unique to your first example because its specific to standard C functions. I have read that 'implicit functions' are basically prototyped as
Code:
int foo()
So that it's return type is int, but nothing is said about its arguments. Note that "foo()" does not mean the function does not accept any arguments--"foo(void)" is used for that case. So I would try some other "simpler" standard functions, i.e. one that matches the implicit function prototype of "int foo()". Maybe in this case you will only get the 1 warning message that you get with your "lnux" function", and not the "incompatible" one.

Last edited by nadroj; 01-17-2010 at 12:18 AM.
 
Old 01-17-2010, 01:15 AM   #5
raju.mopidevi
Senior Member
 
Registered: Jan 2009
Location: vijayawada, India
Distribution: openSUSE 11.2, Ubuntu 9.0.4
Posts: 1,155
Blog Entries: 12

Rep: Reputation: 92
printf() already declared in stdio.h
you have to declare your lnux().
i.e.

/*main.c*/
int lnux(void);
#include<stdio.h>
int main()
{
lnux();
return 0;
}

int lnux(void)
{
return 0;
}
 
Old 01-17-2010, 01:22 AM   #6
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
@nadroj There were actually 2 warnings that's why it's confusing. I only commented on the 2nd one.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
incompatible implicit declaration of built-in function ‘execl’ ? ? ? jiikka Linux - General 3 05-07-2014 03:09 PM
warning: incompatible implicit declaration of built-in function ‘bzero’ nasim751 Linux - Software 3 04-21-2014 03:39 AM
'incompatible implicit declaration' errors when compiling -Pb- Linux - Software 6 11-18-2010 12:39 AM
how to get rid of "warning : implicit declaration of function 'getpid' " ? diodio Linux - Newbie 6 02-01-2006 02:47 PM
warning: incompatible implicit declaration of built-in function ‘exit’ xzotech Programming 1 08-14-2005 05:43 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration