C++ Eclipse Masterclass Now Open!


It’s HERE!

This morning at 9am GMT the C++ Eclipse Masterclass opened for enrolment. Hurrah!

I have poured my heart and soul into creating this course, and I am so proud to finally be launching it today.

It opens with an early bird discount which runs until midnight GMT on 1st June, so if you want to grab a bargain, act now!

If you have any questions, or feedback, please do get in touch.

And thank you, to all of my readers, for your ongoing support and enthusiasm. I wouldn’t be doing any of this without you.

atoi and itoa

atoi and iota seem like perfect partners.

atoi is the ‘ascii to integer’ function and itoa is the reverse, the ‘integer to ascii’ function.

You would use atoi to convert a string, say, “23557” to the actual integer 23557.

Similarly, you would use itoa to convert an integer, say 44711, to the equivalent string “44711”.

Very handy.

Now, if you’ve written a lot of code using Microsoft Visual C++ (which is where I first started when I was learning C and C++), you may not be aware of the fact that atoi is part of the ANSI standard, whereas itoa is not. The MSVC compiler supports itoa, so if you are coding on this platform – particularly if you are learning on this platform – then it appears that atoi and itoa are a complementary pair that would be available everywhere. Not so!

Read more

Fibonacci | Recursively or Not?

You’re probably all aware of the Fibonacci number sequence. Starting with 0 and 1, the next number is determined by the sum of the previous two numbers, so the sequence begins:

0, 1, 1, 2, 3, 5, 8, 13, 21, …

This is a mathematical concept, and it is defined by a “recurrence relation” (that’s a fancy way of saying that each number (or ‘term’) is generated from a previously calculated value), of:

Fn = Fn-1 + Fn-2

with “seed” or starting values of:

F0 = 0 and F1 = 1.

So, as you can imagine, this seems to lend itself nicely to programmatic recursion. Here’s a little program that will give you the 40th number in the Fibonacci sequence, using recursion:

Read more

View A Backtrace For All Threads With GDB

Debugging multi-threaded programs can be really tricky. GDB however, will always do its best to rescue you from whatever horrible bug you’re currently looking at. Today I wanted to show you a really nice command for viewing all the threads in your program.

This particular command is especially helpful if you ever need to diagnose a deadlock, because it will give you a complete overview of the entire system and allow you to see which locks are currently being requested.

I’m going to use the C++11 threads program from my thread tutorial to illustrate, with one minor modification – I’ve added a sleep command in the thread subroutine. The only reason I’ve done this is because it keeps my threads alive for long enough to show them all to you in the debugger. On a commercial multi-threaded system, your threads will be doing something most of the time, so my sleep command is essentially simulating my threads going off and doing important jobs 😉

Read more