1

I'm analyzing a C program in which I find a strange fucntion call here is the function definition :

static void endSignal (int32_t dummy) { if (nTerminating) return; nTerminating=1; printf("terminating....\n"); terminateDLNAsystem(); sleep(1); exit (0); } 

This function takes an int32_t parameter ! Now this the main function calling "endSignal"

int32_t main (int32_t argc, char **argv) { /*Statements . . */ signal(SIGINT, endSignal); signal(SIGABRT, endSignal); signal(SIGQUIT, endSignal); signal(SIGTERM, endSignal); return 0; } 

the main function call endSignal without any parameter, what happen in this case ?

2
  • 1
    It doesn't call endSignal, it passes the function as a parameter to another function. Commented Feb 17, 2017 at 13:14
  • The main prototype is not standard-conforming, BTW; main should return int and the first argument should be int; this in your question is an "other implementation defined manner". Commented Feb 17, 2017 at 13:14

1 Answer 1

6

Main function calls signal functions and not endSignal.

endSignal is parameter acting as callback.

This is passing function pointers as arguments.

How do you pass a function as a parameter in C?

Sign up to request clarification or add additional context in comments.

8 Comments

This is not the same case. in my case "signal" is a pre-defined function in <signal.h> so signal can't call the function endSignal to use it ..
@stojo304 This is exactly the right answer, and of course signal() can call its callback function, that's the whole point. Why shouldn't it be able to?
Yes i just read the definition of signal and understand this point, Thanks
@unwind , please what is the difference between : int *i[]= {1,1}; int j[]={2,2};
first is array of pointers, both points to value 1. In second case, you have 2 integer values, both are set to 1.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.