Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8573879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:21:03+00:00 2026-06-11T19:21:03+00:00

Possible Duplicate: C declaration from standard signal Library Here is a reference to the

  • 0

Possible Duplicate:
C declaration from standard signal Library

Here is a reference to the link for the syntax. I have only understood the syntax of a pointer to a function. But this is too complex please explain.

http://www.cplusplus.com/reference/clibrary/csignal/signal/

I am trying to understand the precise syntax given( some pointer confusion that I can’t resolve ).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T19:21:04+00:00Added an answer on June 11, 2026 at 7:21 pm

    signal() is pretty easy to understand here’s example code from the link I mentioned with my annotations:

    //This is a signal handling function. When your main program gets a signal, it
    // will call this function. The function just prints a message.
    static void catch_function(int signal) {
        printf("Interactive attention signal caught.");
    }
    
    int main(void) {
        //register to catch the interrupt signal.
        if (signal(SIGINT, catch_function) == SIG_ERR) {
            printf("An error occurred while setting a signal handler.\n");
            return EXIT_FAILURE;
        }
        while(1)
        {
          printf("do stuff\n");
          sleep(1);
        }
    }
    

    Now this code will loop forever (doing something), until it gets a ^C (ctrl+C) interrupt signal. At that point in time it will go do whatever it is we told it to do:

    mike@linux-4puc:~> ./a.out 
    do stuff
    do stuff
    ^CInteractive attention signal caught.do stuff
    do stuff
    do stuff
    do stuff
    do stuff
    ^CInteractive attention signal caught.do stuff
    

    The signal function is defined as:

    typedef void (*sighandler_t)(int); //this just means a pointer to a function
                                       //that looks like:  void sighandler(int)
    
    sighandler_t signal(int signum, sighandler_t handler); 
    

    Which means:

    1. A pointer to a function to handle a signal can be referred to “sighandler_t”
    2. A function that meets the sighandler_t type needs to return nothing, and take an int
    3. The signal function then takes the parameters of the signal type to catch, and a function meeting the “sighandler_t” typedef.

    Then at a system level, when our program is running, if a signal comes in and we have handling for it, we do so, if we don’t have handling in place, the OS takes a default action.

    If you remove the signal call from my above example, you’ll see ctrl+C now kills the program instead of just allowing the signal handler to run.

    Answer your question?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: What's your preferred pointer declaration style, and why? In C, why is
Possible Duplicate: What does this ^ syntax mean in Objective-C? I found the declaration
Possible Duplicate: Accessing inherited variable from templated parent class I have been implementing a
Possible Duplicate: What is forward declaration in c++? I just have a question about
Possible Duplicate: What does a CALLBACK declaration in C do? The prototype of a
Possible Duplicate: Porting a C array declaration to Delphi I'm converting a C code
Possible Duplicate: What is the difference between a function expression vs declaration in Javascript?
Possible Duplicate: What do parentheses surrounding a JavaScript object/function/class declaration mean? Why following code
Possible Duplicate: What is useful about this C syntax? C variable declarations after function
Possible Duplicate: Why does second function declaration win even though I return before it?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.