Author Archives: Glennan Carnie

About Glennan Carnie

Glennan is an embedded systems and software engineer with over 20 years experience, mostly in high-integrity systems for the defence and aerospace industry. He specialises in C++, UML, software modelling, Systems Engineering and process development.

Practice makes perfect, part 3 – Idiomatic kata

Previously, we looked at some of the foundational C++ code kata – that is, elements of C++ coding that are absolutely key to master if you’re going to be programming in C++.
Practice makes perfect, part 1 – Code kata
Practice makes perfect, part 2 – foundation kata

In this article I want to introduce what I call ‘idiomatic’ kata.  These exercises have a bit more latitude (and variation) in how they can be implemented.  In that respect they are closer to traditional […]

Posted in C/C++ Programming, Design Issues, training | Tagged , , , | Leave a comment

Practice makes perfect, part 2 – foundation kata

In the previously article we looked at the need for repetitive practice – code kata.  In this article I want to  present some of my preferred foundational kata.

If you’re a beginner to C++ I recommend you fully internalize all these examples before having a look at the idiomatic kata.

If you’re a more experienced C++ programmer you may be looking at these kata and thinking “Jeez – these are so basic!  Who couldn’t do this!”.  Bear in mind though – we […]

Posted in C/C++ Programming, Design Issues, training | Tagged , , , | 1 Comment

Practice makes perfect, part 1 – Code kata

Imagine you’re at a Jazz club, enjoying a smooth jazz quartet.  It’s time for the sax player’s solo.  All of a sudden, he stops the band, rifles in a bag a pulls out a book of music theory.

“What the?!” you think.

The saxophonist looks to the audience, “I’ve just got to look up the notes for E-flat minor.  I can never remember them.”

It’s understandable you’re unlikely be too impressed with this particular musician.

If you’re a musician, a sportsperson, a dancer, martial […]

Posted in C/C++ Programming, Design Issues, training | Tagged , , , , | 3 Comments

Function function return return values values*

The latest C++ standard is now upon us, so it’s time to have a look at some of its new features.

To put one of the new features into context we’re going to have a look at – as the title suggests – multiple function return values

I should really distinguish between the following:

A Subroutine (or Subprogram) is a parameterised block of code that can be called multiple times from within a program.
A Procedure is a subroutine that may have multiple input […]

Posted in C/C++ Programming | Tagged , , , , | Leave a comment

Contract killing (in Modern C++)

If you work in high-integrity or safety-critical software then you have a duty-of-care to:

Ensure your code does what it should
Ensure your code doesn’t do what it’s not supposed to.

Moreover, you’re typically required to both demonstrate and document how you’ve achieved this duty-of-care. Typical mechanisms for demonstrating compliance include unit testing and static analysis; documentation usually includes function specifications and test results. The amount of testing, static analysis and documentation you (have to) do depends on the integrity level of your […]

Posted in C/C++ Programming | Tagged , , , , , , , , , , , , , , | 3 Comments

Celebrating 10 years – my top 10 blog articles

It’s difficult to believe we’ve been writing articles for 10 years.  In that time I’ve written over 90 technical articles on C, C++ and embedded system design.

To celebrate I’ve picked my ‘Top 10’ articles, with a little background into why I enjoyed writing them so much, or the story behind them.

So, sit back, cue up “At the Sign of the Swinging Cymbal“* and enjoy.

 

(* This really dates

Posted in C/C++ Programming, Design Issues, Testing, UML | Tagged , , , , , , , | Leave a comment

Brace initialization of user-defined types

Uniform initialization syntax is one of my favourite features of Modern C++.  I think it’s important, in good quality code, to clearly distinguish between initialization and assignment.

When it comes to user-defined types – structures and classes – brace initialization can throw up a few unexpected issues, and some counter-intuitive results (and errors!).

In this article, I want to have a look at some of the issues with brace initialization of user-defined types – specifically, brace elision and initializer_lists.

Read on for more…

Like (4)

Posted in C/C++ Programming, General | Tagged , , , , , , , | 1 Comment

Thanks for the memory (allocator)

One of the design goals of Modern C++ is to find new ways – better, more effective – of doing things we could already do in C++.  Some might argue this is one of the more frustrating aspects of Modern C++ – if it works, don’t fix it (alternatively: why use lightbulbs when we have perfectly good candles?!)

This time we’ll look at a new aspect of Modern C++:  the Allocator model for dynamic containers.  This is currently experimental, but has […]

Posted in C/C++ Programming, General | Tagged , , , , , , , , , , , | 9 Comments

A brief introduction to Concepts – Part 2

In part 1 of this article we looked at adding requirements to parameters in template code to improve the diagnostic ability of the compiler.  (I’d recommend reading this article first, if you haven’t already)

Previously, we looked at a simple example of adding a small number of requirements on a template parameter to introduce the syntax and semantics.  In reality, the constraints imposed on a template parameter could consist of any combination of

Type traits
Required type aliases
Required member attributes
Required member functions

Explicitly listing […]

Posted in C/C++ Programming | Tagged , , , , , , , | 4 Comments

A brief introduction to Concepts – Part 1

Templates are an extremely powerful – and terrifying – element of C++ programs.  I say “terrifying” – not because templates are particularly hard to use (normally), or even particularly complex to write (normally) – but because when things go wrong the compiler’s output is a tsunami of techno-word-salad that can overwhelm even the experienced programmer.

The problem with generic code is that it isn’t completely generic.  That is, generic code cannot be expected to work on every possible type we could […]

Posted in C/C++ Programming | Tagged , , , , , , , | Leave a comment