In the unix like system, there is a func ptr signal defined as below
at the last line ,but I don't know
how to understand it. becoz the more general to define a func ptr is
the following
void (*signal)(int)
not
#include <signal.h>
void ( * signal(int SIG, void(*FUNC)(int)) )(int);
would anyone help me?
thanks much 6 2188
ooze wrote: In the unix like system, there is a func ptr signal defined as below at the last line but I don't know how to understand it. becoz the more general to define a func ptr is the following:
void (*signal)(int);
not
#include <signal.h> void ( * signal(int SIG, void(*FUNC)(int)) )(int);
cat main.c
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
void hello1(int signum) {
fprintf(stdout, "%d = signum\n", signum);
}
void hello2(int signum) {
fprintf(stdout, "%d = signum\n", signum);
}
int main(int argc, char* argv[]) {
typedef void (*sighandler_t)(int);
// install new signal handlers
sighandler_t oldUSR1sighandler = signal(SIGUSR1, hello1);
sighandler_t oldUSR2sighandler = signal(SIGUSR2, hello2);
while (EOF != getchar());
// restore old signal handlers
signal(SIGUSR2, oldUSR2sighandler);
signal(SIGUSR1, oldUSR1sighandler);
return EXIT_SUCCESS;
}
gcc -Wall -std=c99 -pedantic -o main main.c ./main
Then at a second terminal:
ps -a
PID TTY TIME CMD
21080 pts/21 00:00:01 ssh
21217 pts/22 00:00:01 ssh
22016 pts/23 00:00:00 main
22018 pts/24 00:00:00 ps kill -s USR1 22016
and then, at the first terminal, I get:
10 = signum ./main
and back at the second terminal:
ps -a
PID TTY TIME CMD
21080 pts/21 00:00:01 ssh
21217 pts/22 00:00:01 ssh
22027 pts/23 00:00:00 main
22028 pts/24 00:00:00 ps kill -s USR2 22027
and back, at the first terminal, I get:
12 = signum
On 13 Jul 2004 18:21:58 -0700, fj***@163.net (ooze) wrote: In the unix like system, there is a func ptr signal defined as below at the last line ,but I don't know how to understand it. becoz the more general to define a func ptr is the following void (*signal)(int) not #include <signal.h> void ( * signal(int SIG, void(*FUNC)(int)) )(int);
would anyone help me? thanks much
It helps to redistribute the white space
void(* signal(int SIG, void(*FUNC)(int)) )(int);
This is a function prototype and not the definition of a pointer.
signal is function (not a pointer) that
takes two parameters
an int (called SIG here but that is superfluous)
a pointer (called FUNC but also superfluous) to a function
that takes one parameter (int) and returns void
and returns a pointer to a function that takes an int and returns
void
<<Remove the del for email>>
Emmanuel Delahaye <em**********@noos.fr> wrote in message news:<Xn***************************@212.27.42.71>. .. In 'comp.lang.c', fj***@163.net (ooze) wrote:
In the unix like system, there is a func ptr signal defined as below at the last line ,but I don't know how to understand it. becoz the more general to define a func ptr is the following void (*signal)(int) not #include <signal.h> void ( * signal(int SIG, void(*FUNC)(int)) )(int);
To make it simple, it's a function that returns a pointer to a function. One of the parameter of the function is a pointer to a function. Probably the most terrible syntax of the C language!
It is exactly the case where the use of a typedef is worthy.
typedef void F_TYPE (int);
F_TYPE *signal (int SIG, F_TYPE *FUNC);
what's the differnce of the two declarations?
Emmanuel Delahaye <em**********@noos.fr> wrote in message news:<Xn***************************@212.27.42.71>. .. In 'comp.lang.c', fj***@163.net (ooze) wrote:
In the unix like system, there is a func ptr signal defined as below at the last line ,but I don't know how to understand it. becoz the more general to define a func ptr is the following void (*signal)(int) not #include <signal.h> void ( * signal(int SIG, void(*FUNC)(int)) )(int);
To make it simple, it's a function that returns a pointer to a function. One of the parameter of the function is a pointer to a function. Probably the most terrible syntax of the C language!
It is exactly the case where the use of a typedef is worthy.
typedef void F_TYPE (int);
F_TYPE *signal (int SIG, F_TYPE *FUNC);
what's the differnce of the two declarations? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Nick Coghlan |
last post by:
Time for another random syntax idea. . .
So, I was tinkering in the interactive interpreter, and came up with the
following one-size-fits-most default argument hack:
Py> x = 1
Py> def...
|
by: jack |
last post by:
Hi there,
I have a short question about template function
definition.
1) The following files will not compile in M$ VC++
but will have no problem with g++.
2) However, if I uncomment all...
|
by: Hongzheng Wang |
last post by:
Hi, all.
According to ISO stand, in any function definition block, the
viariables definitions statements must be the first? That is,
int func()
{
int i; /* statement 1 */
double a; /*...
|
by: G Fernandes |
last post by:
Is the following an old-style(K&R) function definition or a new
style(C89)?
int (length, factor, multiple)
{
/* ... code ... */
return length;
}
|
by: nishit.gupta |
last post by:
I was having a problem with template class memer function definition ,
so i serched the net
and find that template class member fuction definition should be in
header file else compilation
will...
|
by: vasudevram |
last post by:
Hi group,
Question: Do eval() and exec not accept a function definition? (like
'def foo: pass) ?
I wrote a function to generate other functions using something like
eval("def foo: ....")
but...
|
by: gsi |
last post by:
Hi,
I looked a while at this but couldnt convice myself of the following reasons in the code.
class A{
int a;
public:
A():a(0){}
void func() {int A::*ptr = &A::a;}
|
by: er |
last post by:
hi,
is anyone aware of a library that generalizes transform, for_each?
e.g.
transform(
vec1.begin(),
vec1.end(),
vec2.begin(),
vec3.begin(),
|
by: eotcl |
last post by:
Dear All!
While looking for the implementation of the printf function, I came
across the implementation
that used the following construct
int printf(const char *format, ...)
What is the...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |