Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

In c++03 and earlier to disable compiler warning about unused parameter I usually use such code:

#define UNUSED(expr) do { (void)(expr); } while (0)

For example

int main(int argc, char *argv[])
{
    UNUSED(argc);
    UNUSED(argv);

    return 0;
}

But macros are not best practice for c++, so. Does any better solution appear with c++11 standard? I mean can I get rid of macros?

Thanks for all!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
271 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can just omit the parameter names:

int main(int, char *[])
{

    return 0;
}

And in the case of main, you can even omit the parameters altogether:

int main()
{
    // no return implies return 0;
}

See "§ 3.6 Start and Termination" in the C++11 Standard.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...