Follow Us
Categories
Archives
- February 2024
- January 2024
- August 2023
- December 2022
- November 2022
- October 2022
- February 2022
- October 2021
- September 2021
- August 2021
- July 2021
- June 2021
- May 2021
- January 2021
- November 2020
- October 2020
- August 2020
- April 2020
- February 2020
- January 2020
- October 2019
- September 2019
- July 2019
- May 2019
- April 2019
- March 2019
- February 2019
- January 2019
- December 2018
- October 2018
- September 2018
- August 2018
- July 2018
- April 2018
- February 2018
- January 2018
- December 2017
- November 2017
- October 2017
- September 2017
- August 2017
- July 2017
- June 2017
- May 2017
- April 2017
- March 2017
- February 2017
- January 2017
- December 2016
- November 2016
- October 2016
- September 2016
- August 2016
- July 2016
- April 2016
- January 2016
- December 2015
- November 2015
- October 2015
- September 2015
- August 2015
- July 2015
- June 2015
- May 2015
- January 2015
- December 2014
- November 2014
- October 2014
- September 2014
- August 2014
- July 2014
- June 2014
- May 2014
- April 2014
- March 2014
- February 2014
- January 2014
- November 2013
- September 2013
- August 2013
- July 2013
- June 2013
- May 2013
- April 2013
- February 2013
- January 2013
- November 2012
- October 2012
- August 2012
- July 2012
- June 2012
- May 2012
- April 2012
- March 2012
- December 2011
- November 2011
- June 2011
- May 2011
- April 2011
- March 2011
- February 2011
- January 2011
- December 2010
- November 2010
- October 2010
- September 2010
- August 2010
- July 2010
- June 2010
- May 2010
- April 2010
- March 2010
- February 2010
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009
Author Archives: Glennan Carnie
Bitesize Modern C++: nullptr
What’s the value of a null pointer?
0
NULL
NUL
No doubt you’ve been involved in the (always heated) discussions about which is the correct one (By the way, if you said NUL you need to take yourself to one side and give yourself a stern talking to).
The arguments tend to go something like this:
0 is the only ‘well-known’ value a pointer can be set to that can be checked.
NULL is more explicit than just writing zero (even though it is just a […]
Bitesize Modern C++: enum class
Enumerated types in C++ give a trivial simulation of symbolic types – that is, objects whose instances have unique, human-readable values. In C++ enumerations are essentially named integers that are either assigned values implicitly by the compiler or explicitly by the programmer (or a combination of both)
C++ enum types inherit their semantics from C with some additions:
enum objects are now first-class types
enums may be implicitly converted to integers; but the reverse is not true
Another characteristic illustrated in the […]
Bitesize Modern C++ : static_assert
C’s assert library is a useful tool for catching invalid invariants (conditions that must hold true in order for your system to operate as specified) in your program. The big problem with assert is that it’s a run-time check; in many cases the best you can do to recover from an assert failure is restart the system or put it into a quiescent state.
In a lot of cases the (faulty) invariants could be detected at compile-time but in C++98 there […]
Bitesize Modern C++ : constexpr
A constant expression is an expression that can be evaluated at compile-time. The const qualifier gives a weak guarantee of a constant expression – a const-qualified type may not be changed after initialisation but that does not guarantee it will be initialised at compile-time. For example:
C++11 introduces a strong form of constant expression, constexpr, which also expands the capabilities of compile-time evaluation.
constexpr objects
A constexpr variable is essentially the same as qualifying the type as const with the additional requirement that […]
Posted in C/C++ Programming
Tagged C++, C++0x, C++11, constexpr, constructor, Modern C++
Leave a comment
Bitesize Modern C++ : auto
C++ is a statically-typed language, that is, you must explicitly declare the type of every object before use. The type of an object specifies
The amount of memory occupied
How the memory (bits) is interpreted
The operations allowable on the object
An object’s type is fixed at declaration – unless the programmer chooses to circumvent the type system using a cast.
Often for C++ objects specifying the type can be onerous:
C++11 allows automatic type-deduction to simplify the creation and maintenance of code.
The […]
Bitesize Modern C++
The C++11 standard marked a fundamental change to the C++ language. A range of new language constructs and library features were added and, as a result, new idioms were developed. Bjarne Stroustrup, originator of C++, referred to it as “feeling like a completely new language”.
In 2014 a revision of the standard was released with refinements to C++11 features and some new constructs, designed to improve the usability of the language; another revision is planned for 2017.
Traditionally, C++ programmers refer to […]
The Rule of Zero
In a previous article – ”The Rule of the Big Four (and a half)” we looked at resource management policies in C++.
Resource management is the general term for using the mechanisms in C++ to ensure that resources – files, dynamic memory, sockets, mutexes, etc – have their lifetimes automatically controlled so as to prevent resource leaks, deadlocks, etc. C++ refers to these mechanisms as RAII/RDID ( “Resource Acquisition Is Initialisation / Resource Destruction is Deletion”)
In this article we’ll have a […]
The Rule of The Big Four (and a half) – Move Semantics and Resource Management
In the previous article we looked at the issues of resource management in C++ and introduced “The Rule of The Big Three (and a half)”. In this article we’ll extend this concept by looking at the idea of move semantics, a feature introduced in C++11. Move semantics mean we’ll have to extend our rule to “The Rule of The Big Five” or, perhaps more correctly, “The Rule of The Big Four (and a
The Rule of The Big Three (and a half) – Resource Management in C++
The dynamic creation and destruction of objects was always one of the bugbears of C. It required the programmer to (manually) control the allocation of memory for the object, handle the object’s initialisation then ensure that the object was safely cleaned-up after use and its memory returned to the heap. Because many C programmers weren’t educated in the potential problems (or were just plain lazy or delinquent in their programming) C got a reputation in some quarters for being an […]
Posted in C/C++ Programming
Tagged Copy-swap idiom, Release Management, Rule of the Big Three
7 Comments
Software Duct Tape – Binding the C++ Universe Together
One of the cornerstones of object-oriented design is the concept of objects interacting by sending messages to form mechanisms – units of higher-order (or ‘emergent’) behaviour.
In order to send a message (in this case, invoke a member function) an object must have a ‘link’ to the target object. That link is formed by building in an association between the two classes as part of the type’s definition.
In this article we look at building associations between classes and forming run-time links […]