|
|
header's included but still get 'implicit declaration'
Hello, All!
I'm compiling this with "gcc -W -Wall -ansi -pedantic" and getting:
storage size of `act' isn't known
warning: implicit declaration of function `sigfillset'
warning: implicit declaration of function `sigaction'
unused variable `act'
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <signal.h>
#include <linux/if_ether.h>
#include <linux/ip.h>
#include <linux/tcp.h>
#include "my.h"
....
void mode_off()
{
....
}
int main(void)
{
static struct sigaction act;
act.sa_handler = mode_off;
sigfillset(&(act.sa_mask));
sigaction(SIGINT, &act, NULL);
...
return 0;
}
Might be on Linux there is difference in what order the header files are
included?
I'm definetely using 'act' variable, but get 'unused variable' message, why?
And I've included proper header declaring and defining 'sigfillset' and
'sigaction', but anyway get this warning.
Thanks in advance.
With best regards, Roman Mashak. E-mail: mrv@tusur.ru
|
|
0
|
|
|
|
Reply
|
Roman
|
11/8/2005 8:38:56 AM |
|
I vaguely remember having the same errors in the past; IIRC, I solved
that issue or substituting -ansi with -std=c99 or adding a
-D__USE_POSIX in the compilation.
--
Maurizio Loreti http://www.pd.infn.it/~loreti/mlo.html
Dept. of Physics, Univ. of Padova, Italy ROT13: ybergv@cq.vasa.vg
|
|
0
|
|
|
|
Reply
|
Maurizio
|
11/8/2005 7:13:44 AM
|
|
Hello, Maurizio!
You wrote on 08 Nov 2005 08:13:44 +0100:
ML> I vaguely remember having the same errors in the past; IIRC, I solved
ML> that issue or substituting -ansi with -std=c99 or adding a
ML> -D__USE_POSIX in the compilation.
Thank you, this method helped me out, but what's the reason of such a
strange behavior?
With best regards, Roman Mashak. E-mail: mrv@tusur.ru
|
|
0
|
|
|
|
Reply
|
Roman
|
11/8/2005 11:02:16 AM
|
|
"Roman Mashak" <mrv@tusur.ru> wrote in message
news:dkppgi$3rk$1@relay.tomsk.ru...
> Hello, Maurizio!
> You wrote on 08 Nov 2005 08:13:44 +0100:
>
> ML> I vaguely remember having the same errors in the past; IIRC, I solved
> ML> that issue or substituting -ansi with -std=c99 or adding a
> ML> -D__USE_POSIX in the compilation.
> Thank you, this method helped me out, but what's the reason of such a
> strange behavior?
When you use gcc with -ansi -pedantic, extensions (such as POSIX APIs) are
made unavailable; the compiler acts as a "pure" C compiler, conformant with
the ANSI standard (or at least its best impersonation of one) and nothing
more.
__USE_POSIX is glibc-specific and not intended to be specified by the user.
If (as I suspect is the case) you are using glibc, you may find reading
/usr/include/features.h instructive. You should probably define
_POSIX_SOURCE or _POSIX_C_SOURCE.
Alex
|
|
0
|
|
|
|
Reply
|
Alex
|
11/8/2005 12:34:25 PM
|
|
"Roman Mashak" <mrv@tusur.ru> wrote:
>Hello, Maurizio!
>You wrote on 08 Nov 2005 08:13:44 +0100:
>
> ML> I vaguely remember having the same errors in the past; IIRC, I solved
> ML> that issue or substituting -ansi with -std=c99 or adding a
> ML> -D__USE_POSIX in the compilation.
That's close, and uses the right concept, but isn't quite right.
>Thank you, this method helped me out, but what's the reason of such a
>strange behavior?
Take a look at /usr/include/features.h for more information on
what is avaiable and what each flag does.
The significance is that flags starting with a double underscore
are for the use of the implementation (hence you should not
directly define __USE_POSIX), while flags with a single
underscore are "defined by the user (or the compiler) to specify
the desired environment".
Rather than __USE_POSIX, one might want to use any of (probably
in the order of least likely to most likely)
_POSIX_SOURCE
_POSIX_C_SOURCE
_BSD_SOURCE or _SVID_SOURCE
_GNU_SOURCE
Note that _POSIX_C_SOURCE might be defined with any of a number
of values, invoke different posix compliance levels.
But the most important thing, which is often seen done
incorrectly in code posted to Usenet, is that the define must
come *before* various header files are included! Hence the use
of a compiler switch as shown above is correct, or it can be
done in the source code file like this:
#define _GNU_SOURCE
#include <stdio.h>
...
--
FloydL. Davidson http://www.apaflo.com/floyd_davidson
Ukpeagvik (Barrow, Alaska) floyd@apaflo.com
|
|
0
|
|
|
|
Reply
|
Floyd
|
11/8/2005 3:32:30 PM
|
|
|
4 Replies
568 Views
(page loaded in 0.073 seconds)
|
|
|
|
|
|
|
|
|