0

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;
}
Yu Hao
  • 115,525
  • 42
  • 225
  • 281
user997112
  • 26,971
  • 40
  • 166
  • 315
  • 3
    It has one variable name: `rl`. If this is C++, the `struct` isn't needed, and if this is C, you can change the type so it isn't needed. – chris Apr 01 '14 at 00:45

2 Answers2

2

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

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

Yu Hao
  • 115,525
  • 42
  • 225
  • 281
1

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.

Community
  • 1
  • 1
Leif Andersen
  • 20,277
  • 17
  • 65
  • 97