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
  • 119,891
  • 44
  • 235
  • 294
user997112
  • 29,025
  • 43
  • 182
  • 361
  • 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
  • 119,891
  • 44
  • 235
  • 294
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
  • 21,580
  • 20
  • 67
  • 100