Access GDB Directly In Eclipse Luna

This isn’t a new feature, but it’s really useful when you’re debugging in eclipse, especially if you’re using the more advance or obscure features in GDB.

Basically, when you are debugging any program, there is a way to talk directly to GDB without using the point-and-click interface of Eclipse.

It’s called the GDB console.

It’s also really easy to find. When you are next running a debug session, just click on the console icon that is displayed in the console tab. The console usually shows your program output, but there is more than just one console!

Read moreAccess GDB Directly In Eclipse Luna

The extern Keyword

After all the recent posts about statics, I wanted to talk about the extern keyword before moving onto something different.

Do you remember the problem we had with our “global” static variable in this post? If you haven’t read it, the code example illustrated that static variables are only available to code in the translation unit. That means that if you include a file with a static variable in several of your other files, you won’t just have one copy of that variable. This is really important, because you could run into a nasty bug if you are accessing the static variable thinking that it is the same one across all the files you are using it in.

The extern keyword provides the solution to this, as it allows you to create a true global variable that will be available across all files and all translation units.

Read moreThe extern Keyword

Static Variables In Template Classes And Methods

This is the final post in a series on static variables, and in it I’ll talk about the final place we can put them – in template classes or functions.

If you’ve been following along, and you have a good understanding of how template classes work, you can almost certainly deduce how static variables will perform in this situation.

Essentially, because a template class is exactly that – a template – any static variables declared within it are only created if the template class is actually used to create a type.

Let’s quickly run through the basics of what a template class is, then the way that static variables behave will become clearer.

Read moreStatic Variables In Template Classes And Methods

Static Variables In C++ Classes

It turns out that static variables in C++ classes are actually pretty cool.

If you declare a static variable at class level (i.e. inside the class declaration), then you are creating a variable that will

a) be accessible to all objects created from that class, and
b) be available even before you have created a single instance of that class.

Essentially, every object you create sees the same static variable, so anything that one object does to that variable (such as increment the value), all the other objects can also see.

Super useful, eh?

Read moreStatic Variables In C++ Classes