Re: Anything to worry about (compiler warnings)?
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Wed, 08 Apr 2009 19:12:46 -0700
CBFalconer <cbfalconer@xxxxxxxxx> writes:
Zach wrote:
My program opens a file then associates a stream with it using
fdopen. Then it reads from the stream into the buffer. I am
getting a few warnings. I compiled with very strict options:
gcc -g -W -Wall -std=c99 -pedantic
So I wanted to know if these warnings are something to worry
about (need fixing) or if I can just ignore them:
main5.c: In function main:
main5.c:30: warning: implicit declaration of function fdopen
main5.c:30: warning: assignment makes pointer from integer
without a cast
main5.c: At top level:
main5.c:11: warning: unused parameter argc
Here is my code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
Yes, you need to worry. You are asking for compilation to C99
standards (the -std=c99 and -pedantic above). The last four
include files specified don't exist in C99, and neither does
fdopen.
The last four include files may (or may not) exist in a conforming C99
implementation. They make the code non-portable, not incorrect.
Are you under the impression that the C99 standard forbids
non-portable code? Shall I cite the section of the C99 standard that
specifically permits extensions?
I don't know where you are getting the 'pointer from integer'
error.
It's on the same line as the warning about the fdopen function.
Because the declaration of fdopen is not visible to the compiler, the
compiler is implicitly assuming that it returns int, and he's
assigning the result to a pointer object. (Making this assumption in
C99 mode is questionable, but as long as the required diagnostic is
printed, it's not a conformance problem.)
You are also calling other things that don't exist in standard C.
Such as 'open'. Use fopen. You should have gotten warnings on
this. Maybe there is something around that lets you access the
non-existing standard headers mentioned above.
Why on Earth should the compiler warn about a call to open()? As it
happens, the open function is declared in the (non-standard) header
<fcntl.h>. He has a "#include <fcntl.h>" at the top of his code. The
call is perfectly valid *for an implementation that supports it*.
And why should he call fopen() rather than open()? If he wants to ask
about open(), he should do so in comp.unix.programmer (as he's already
been advised several times), but there are valid system-specific
reasons to use open() rather than fopen(). (In this case, he later
calls fstat().)
Failure to use argc implies that you can access missing parameters.
Correct.
--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.
- Follow-Ups:
- Re: Anything to worry about (compiler warnings)?
- From: Mark McIntyre
- Re: Anything to worry about (compiler warnings)?
- From: Antoninus Twink
- Re: Anything to worry about (compiler warnings)?
- References:
- Anything to worry about (compiler warnings)?
- From: Zach
- Re: Anything to worry about (compiler warnings)?
- From: CBFalconer
- Anything to worry about (compiler warnings)?
- Prev by Date: Re: structure and union queries
- Next by Date: Re: Whats the legal state of @ character in identifiers?
- Previous by thread: Re: Anything to worry about (compiler warnings)?
- Next by thread: Re: Anything to worry about (compiler warnings)?
- Index(es):
Relevant Pages
|