|
Home > Archive > Unix Programming > December 2005 > some confused warning
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
some confused warning
|
|
|
| >cat test.c
////////////////////////////////////////////////////////////////////
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <stdarg.h>
/////////////////////////////////////////////////////////
#define MAXLINE 4096
//////////////////////////////////////////////////////////
static void err_doit(int, const char *, va_list);
////////////////////////////////////////////////////////////
int main(void)
{
if (open("tempfile", O_RDWR) < 0)
err_sys("open error");
if (unlink("tempfile") < 0)
err_sys("unlink error");
printf("file unlinked\n");
sleep(15);
printf("done\n");
exit(0);
}
////////////////////////////////////////////////////////////////
void err_sys(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
err_doit(1, fmt,ap);
va_end(ap);
exit(1);
}
///////////////////////////////////////////////////////////////////
static void err_doit(int errnoflag, const char *fmt, va_list ap)
{
int errno_save;
char buf[MAXLINE];
errno_save = errno;
vsprintf(buf, fmt, ap);
if (errnoflag)
sprintf(buf + strlen(buf), ": %s", strerror(errno_save));
strcat(buf, "\n");
fflush(stdout);
fputs(buf, stderr);
fflush(NULL);
return;
}
/////////////////////////////////////////////////////////////////////
>gcc -o test test.c
test.c:29: warning: type mismatch with previous implicit declaration
test.c:16: warning: previous implicit declaration of `err_sys'
test.c:29: warning: `err_sys' was previously implicitly declared to
return `int
/////////////////////////////////////////////////////////////////////////
| |
| Paul Pluzhnikov 2005-12-28, 2:54 am |
| Final <k00kyy@gmail.com> writes:
> test.c:29: warning: type mismatch with previous implicit declaration
> test.c:16: warning: previous implicit declaration of `err_sys'
> test.c:29: warning: `err_sys' was previously implicitly declared to return `int
The warning is correct and not confused at all.
Perhaps you meant "confusing"?
Did you have a question about it?
Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
| |
| Lew Pitcher 2005-12-28, 2:54 am |
| -----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Final wrote:
>
> ////////////////////////////////////////////////////////////////////
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <fcntl.h>
> #include <stdio.h>
> #include <unistd.h>
> #include <errno.h>
> #include <stdarg.h>
> /////////////////////////////////////////////////////////
> #define MAXLINE 4096
> //////////////////////////////////////////////////////////
> static void err_doit(int, const char *, va_list);
> ////////////////////////////////////////////////////////////
> int main(void)
> {
> if (open("tempfile", O_RDWR) < 0)
> err_sys("open error");
>
> if (unlink("tempfile") < 0)
> err_sys("unlink error");
>
> printf("file unlinked\n");
> sleep(15);
> printf("done\n");
>
> exit(0);
> }
> ////////////////////////////////////////////////////////////////
> void err_sys(const char *fmt, ...)
> {
> va_list ap;
> va_start(ap, fmt);
> err_doit(1, fmt,ap);
> va_end(ap);
> exit(1);
> }
> ///////////////////////////////////////////////////////////////////
> static void err_doit(int errnoflag, const char *fmt, va_list ap)
> {
> int errno_save;
> char buf[MAXLINE];
>
> errno_save = errno;
> vsprintf(buf, fmt, ap);
> if (errnoflag)
> sprintf(buf + strlen(buf), ": %s", strerror(errno_save));
> strcat(buf, "\n");
> fflush(stdout);
> fputs(buf, stderr);
> fflush(NULL);
> return;
> }
> /////////////////////////////////////////////////////////////////////
>
>
> test.c:29: warning: type mismatch with previous implicit declaration
> test.c:16: warning: previous implicit declaration of `err_sys'
> test.c:29: warning: `err_sys' was previously implicitly declared to
> return `int
Seems self explanatory. The first occurrance of err_sys is on line 16. By that
point, you have not provided a prototype for the err_sys function, so the
language defaults err_sys() to "function returning int".
Later (line 29), you provide a function definition for the err_sys() function
that does not agree with the usage in line 16 (at line 29, you define
void err_sys(const char *fmt, ...)
which disagrees with the implicit definition of
int err_sys()
from line 16).
So, you need to fix your code.
- --
Lew Pitcher
Master Codewright & JOAT-in-training | GPG public key available on request
Registered Linux User #112576 (http://counter.li.org/)
Slackware - Because I know what I'm doing.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.7 (GNU/Linux)
iD8DBQFDsiL/ agVFX4UWr64RAqtmAJ9GLAbLAmOBBlGszRodMpsf
6SDIzQCg8scR
6NzPEdpiM8bTyOupfUYJ9OY=
=Q6ZG
-----END PGP SIGNATURE-----
| |
|
| Lew Pitcher дµÀ:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Final wrote:
>
>
>
>
> Seems self explanatory. The first occurrance of err_sys is on line 16. By that
> point, you have not provided a prototype for the err_sys function, so the
> language defaults err_sys() to "function returning int".
>
> Later (line 29), you provide a function definition for the err_sys() function
> that does not agree with the usage in line 16 (at line 29, you define
> void err_sys(const char *fmt, ...)
> which disagrees with the implicit definition of
> int err_sys()
> from line 16).
>
> So, you need to fix your code.
>
> - --
> Lew Pitcher
>
> Master Codewright & JOAT-in-training | GPG public key available on request
> Registered Linux User #112576 (http://counter.li.org/)
> Slackware - Because I know what I'm doing.
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.7 (GNU/Linux)
>
> iD8DBQFDsiL/ agVFX4UWr64RAqtmAJ9GLAbLAmOBBlGszRodMpsf
6SDIzQCg8scR
> 6NzPEdpiM8bTyOupfUYJ9OY=
> =Q6ZG
> -----END PGP SIGNATURE-----
You are right.
|
|
|
|
|