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;
}
1
  • 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. Commented Apr 1, 2014 at 0:45

2 Answers 2

2

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

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

Sign up to request clarification or add additional context in comments.

2 Comments

Ah so rlimit is a "type" of struct?
@user997112 In C, struct rlimit is a type, rlimit alone is just a struct tag.
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.