Tag Archives: c programming

Static Variables in C and C++ – File Level

When is a global not a global? When it’s a static variable. This post, and the next three, will talk about static variables. Let’s start with static variables declared in a file. Static variables in a file If you declare a static variable at file level (i.e. not inside any other code), then you are […]

Friend Functions And Classes In C++

The friend keyword in C++ is one of those concepts that is formally taught, but then seems to disappear off the scene once you get into the real world. Maybe friends are less common in embedded programming (ha ha), but I’ve seen very few of them over the years. The thing is, they just don’t seem to […]

Inclusion Guards

Just to clear up what we’re talking about, an inclusion guard looks like this: #ifndef HEADER_FILE_H #define HEADER_FILE_H …//your header #endif //HEADER_FILE_H It consists of three preprocessor directives around the code of your header file. Most IDEs add these for you automatically when you create a header, but it’s well worth having an appreciation of why […]

What Does The Preprocessor Do?

What a jolly good question. The preprocessor takes a look at your source code just before it goes off to the compiler, does a little formatting, and carries out any instructions you have given it. Like what? Well, preprocessor instructions are called preprocessor directives, and they all start with a #. Like #include? Exactly. Each […]