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
The hokey-cokey* of function calls
Functions are the lifeblood of a C program. The program flow is altered by passing parameters to functions, which are then manipulated. Conceptually function parameters are defined as being either:
Inputs (Read-only) – client-supplied objects manipulated within the function only
Outputs (Write-only) – objects generated by the function for use by the client.
Input-Outputs (Read-Write) – client objects that can be manipulated by the function.
Defining the use of a parameter gives vital information not only to the implementer, but (perhaps more importantly) to […]
Posted in C/C++ Programming, Design Issues
Tagged C Declarations, functions, interface, parameters, quality, safety, security
Leave a comment
Shock horror! I learned something about arrays in C
Every so often you pick up a snippet of information that completely changes the way you view things. This week, it’s the use of arrays as function parameters.
At first glance the code horrified me (as I’m sure it will horrify some of you out there!) but as I’ve played with it I can see real merit in the technique.
Arrays, pointers and syntactic sugar
In C there is a close (if somewhat messy!) relationship between arrays and pointers. As far as the […]
Casting – what could possibly go wrong?
Type casting in C++ is a form of what is known in computer science as type punning – that is, circumventing the type system of a programming language.
C++ inherits its conversion and casting mechanism from C, but supplements it (although sensibly we should say, replaces it) with four, more explicit cast operations:
static_cast
reinterpret_cast
const_cast
dynamic_cast
In C and C++ – and particularly in embedded systems – casting is a necessary evil; so much so that many programmers just accept it […]
Posted in C/C++ Programming, Design Issues
Tagged casting, const_cast, dynamic_cast, reinterpret_cast, RTTI, static_cast
1 Comment
The Rule of the Big Five
The dynamic creation and destruction of objects was always one of the bugbears of C. It requires the programmer to manually control the allocation, initialisation and deallocation of memory for the object. 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 unsafe, memory-leaking language.
C++ improved matters significantly with an idiom known as RAII/RRID; more generically referred to as resource […]
Namespaces
In this article we look at one of the issues inherent in C when building larger projects – the problem of function and object naming. We look at the C++ solution to this: namespaces.
A problem with big projects in C
When we move to multi-file projects the problem in C is having to create unique names for functions and externs in the global namespace. If we don’t have unique definitions this will lead to a link-time error.
We could, of course, make […]
Debunking priority
Before I start, a disclaimer:
For the purposes of this article I’m limiting the discussion to even-driven systems on priority-based, pre-emptive operating systems, on single processors.
I’m using the word task to mean ‘unit of execution’ or ‘unit of schedulability’, in preference to thread or process. I’m ignoring the different OS memory models.
There seems to be a fair amount of misunderstanding about the concept of priority in concurrent programming:
Priority means one task is more ’important’ than another.
Priority allows one task to […]
Posted in Design Issues, RTOS
Tagged event-driven, multi-tasking, multi-threading, priority, RTOS, task
Leave a comment
L-values, r-values, expressions and types
Simple question: Why does this code compile?
…and this code doesn’t?
The compiler gives the following:
L-values
What is this ‘l-value’ thing? When (most of us) were taught C we were told an l-value is a value that can be placed on the left-hand-side of an assignment expression. However, that doesn’t give much of a clue as to what might constitute an l-value; so most of the time we resort to guessing and trial-and-error.
Basically, an l-value is a named object; which may be modifiable […]
Sailing the Seven C’s of design*
I’m always looking for nice little mnemonics to help out remember the important concepts in design. Here’s one for model-driven development I call the “Seven C’s”. It basically enumerates the seven stages a design goes through, from initial idea to code.
CONCEPT The Concept phase is about understanding the problem. In other words: requirements analysis. When you’re in Concept mode your main focus is on validation – am I solving the right problem for my […]
Posted in Design Issues
Tagged design, MDA, MDD, methodologies, modelling, techniques, UML
2 Comments
Default construction and initialisation in C++11
Default constructors
In C++ if you don’t provide a constructor for the class the compiler provides one for you (that does nothing):
This, of course, isn’t very useful so typically we write our own constructors to initialise the attributes of our class. However, as soon as you write a (non-default) constructor the compiler stops providing the default constructor:
The normal solution is to write our own default constructor. In C++11 there is syntax to allow you to explicitly create the compiler-supplied constructor without […]
Posted in General
2 Comments
The changing face of programming abstraction in C++
Iterating through containers… options, options options.
Iterating through a container of objects is something we do a lot. It’s boilerplate code. It’s also a nice indicator of how C++ is raising the level of abstraction in programming.
So let’s start with a simple container of ADTs:
Now let’s iterate through them, calling the mf() method on each object in turn. First, we’ll ‘roll our own’ loop.
That’s imperative programming in action; and has the warm, fuzzy feeling of recognition for all C programmers.
Modern C++, […]
Posted in C/C++ Programming
Tagged abstraction, C++11, C++98, efficiency, iteration, language
1 Comment