Manoj Rao bio photo

Manoj Rao

Your Average Common Man

Email Twitter Github

Remember the annoying warnings that you feel helpless about? Well you shouldn’t because C++-11 introduced Attributes which are indicators to the compiler to either disable a warning or to flag a warning.

C++-17 introduced three main Attributes which are helpful.

[[nodiscard]]

As the name suggests, by annotating the code with [[nodiscard]] you are telling the compiler that the values returned should not be discarded. This is usefull when ignoring the returned value can cause errors in the program.

[[maybe_unused]]

In many cases, some of the variables or values allocated may not be used. Example for this are function parameters that are not used, or data members of a structure or a Class that are not used.

[[fallthrough]]

You have a switch statement and certain cases may not have an explicit break statement. In such cases, the compiler usually throws a warning. To avoid these warnings we should explicitly add [[fallthrough]] statements.

Source

C++17 - The Complete Guide


My Podcast!

If you like topics such as this then please consider subscribing to my podcast. I talk to some of the stalwarts in tech and ask them what their favorite productivity hacks are:

Available on iTunes Podcast

Visit Void Star Podcast’s page on iTunes Podcast Portal. Please Click ‘Subscribe’, leave a comment.

Get it iTunes

Available on Google Play Music

Visit Void Star Podcast’s page on Google Play Music. Please Click ‘Subscribe’ and leave a comment.

Listen on Google Play Music
Available on Stitcher

Visit Void Star Podcast’s page on Sticher. Please Click ‘Subscribe’ and leave a comment.

Listen to Stitcher

Your app not listed here? Not an issue..

You should be able to search for ‘VoidStar Podcast’ on your favorite app. Most apps use one of the above sources for listing podcasts. This was tested on Podcast Addict (where you can also specify the search engine) and RatPoison on Android.