Deepak
Deepak

Reputation: 480

sigaction both struct and function

The following code compiles,

struct sigaction sa;
memset (&sa, 0, sizeof (sa));
sa.sa_handler = &handler;
sigaction (SIGRTMIN + 5, &sa, NULL);

but if I omit struct it gives me error:

expected ';' before 'sa'

I am using c++ in which using struct keyword is not necessory.

How does it work when I use struct.

Upvotes: 2

Views: 1508

Answers (1)

James Kanze
James Kanze

Reputation: 153977

In C, structure tags were in a separate name space than other names, so they couldn't conflict. In C++, there is a special hack in the language to support this: in addition to the usual function overloading, you can have two identical symbols in the same scope, provide one is a type name specifying a class type or an enum. When the name is looked up, the compiler will choose the one which is not a type name unless the name immediately follows a class-key (class, struct or union) or the keyword enum.

Upvotes: 7

Related Questions