user997112
user997112

Reputation: 30655

Why does struct have two variable names in C/C++

In the below code why does the struct have two variable names?

#include <sys/resource.h>

int main (int argc, char **argv)
{
    const rlim_t kStackSize = 64L * 1024L * 1024L;

    struct rlimit rl;    //HERE

    int result = getrlimit(RLIMIT_STACK, &rl);


    return 0;
}

Upvotes: 0

Views: 183

Answers (2)

Leif Andersen
Leif Andersen

Reputation: 22342

If this is C, the struct is just to tell C that it is in a different namespace.

See: understanding C namespaces

If this is C+++, then the struct is not needed.

Upvotes: 1

Yu Hao
Yu Hao

Reputation: 122493

In C, struct with its tag together is a name, unless it's typedefed.

In C++, you can omit the struct keyword.

Upvotes: 2

Related Questions