"implicit declaration of function printf" 
Author Message
 "implicit declaration of function printf"

Could someone take a moment to tell me why the following line
of code gives the above warning?

printf("%d\n", pil->list[i]);

I am attempting to print an array of integers.

When I ran cdecl, I got "Bad ()'s".  I've been staring at the
code too long and would appreciate a hint.  

With thanks,

Christina



Thu, 05 Jul 2001 03:00:00 GMT  
 "implicit declaration of function printf"


Quote:
>Could someone take a moment to tell me why the following line
>of code gives the above warning?

>printf("%d\n", pil->list[i]);

An implicit declaration of printf() suggests that you forgot to
#include <stdio.h> which would provide a suitable declaration. Note that
since printf() is a variable argument function it is an error (i.e.
undefined behaviour) to call it without a suitable declaration in scope.

--
-----------------------------------------


-----------------------------------------



Thu, 05 Jul 2001 03:00:00 GMT  
 "implicit declaration of function printf"

Quote:

> Could someone take a moment to tell me why the following line
> of code gives the above warning?

Because you left out
#include <stdio.h>

--




Thu, 05 Jul 2001 03:00:00 GMT  
 "implicit declaration of function printf"
: Could someone take a moment to tell me why the following line
: of code gives the above warning?

: printf("%d\n", pil->list[i]);

: I am attempting to print an array of integers.

: When I ran cdecl, I got "Bad ()'s".  I've been staring at the
: code too long and would appreciate a hint.  

'Implicit declaration' means that there's no declaration in
scope for printf(), and the compiler's made up its own from
this call.  Not a good idea; at a guess, you haven't included
stdio.h where printf() is prototyped.

Will



Thu, 05 Jul 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. "extern" and function declarations

2. "noalias" in library function declarations

3. Q error "invalid function declaration"

4. "implicit..." - thanks

5. "remove implicit int"

6. Help: "warning: implicit declaration of function `bzero'" with string.h included

7. Old meaning of "long double" declaration

8. printf("%d",1.0/3*3)

9. Inconsistent type declaration: "iconv_t"

10. printf("/033E")

11. printf("%g") to 3 sig figs

12. Behaviour of printf("[%.0g]",1.0)

 

 
Powered by phpBB® Forum Software