How can sigaction be both a structure and a function?

I noticed that sigaction

both the struct and the function are defined ( http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html ):

    int sigaction(int, const struct sigaction *restrict,
       struct sigaction *restrict);

      

And an example of use:

    struct sigaction sa;

    /* Set up handler */
    sa.sa_flags = SA_SIGINFO|SA_RESTART;
    sa.sa_sigaction = timer_expiry;

    /* Setup signal watchdog */
    if (sigaction(SIG_WDOG, &sa, NULL) == -1) {
       printf("ERROR: Failed to set wdog signal with %s",
           strerror(errno));
    }

      

+3


source to share


1 answer


C has several namespaces for identifiers; and function ids and structure tag ids live in different namespaces.

(C11, 6.2.3 Identifier spaces p1) "If at any point in the translation unit, the syntactic context ambiguously uses usage referring to different entities. Thus, there are separate namespaces for different categories of identifiers:

  • label names (ambiguous by the syntax of label declaration and use);

  • structure, union, and enumeration tags (ambiguously following any 32) of the keyword struct, union or enum);

  • members of structures or unions; each structure or union has a separate namespace for its members (an ambiguous expression used to access an element via. or β†’);

  • all other identifiers called regular identifiers (declared in regular declarators or enumeration constants)



...

+5


source







All Articles