basics

The Evolving Search for Effective C++ --Scott Meyers

Scott Meyers' keynote at the Meeting C++ 2014 conference. A short description can be found on 

the presenters blog.

The Evolving Search for Effective C++

by Scott Meyers

Description from the blog:

The video of my keynote address at Meeting C++ 2014 on December 5 has just been posted to the Meeting C++ Channel at YouTube. I was given a long time slot (two hours), so I addressed two rather different topics, both based on my work of the past quarter century identifying and promulgating guidelines for effective C++ programming...

Using assertions -- Andrzej Krzemieński

Today on Andrzej's blog:

Using assertions

by Andrzej Krzemieński

From the article:

This post is a response to my recent encounters with fellow programmers who appear to me to be missing the point of assertions and fail to appreciate their usefulness. The first post I have ever written here was on assertions, I still find it good, so there is no need to repeat it; here I will only describe how I observe people treat assertions and why I believe it is wrong.

I am reviewing the following code...

Android NDK Revision 10d available

For all the people that develop for Android, a new version( revision 10d) of the Android Native Development Kit has been released.

Android NDK Revision 10d available

From the release log:

  • Made GCC 4.8 the default for all 32-bit ABIs. Deprecated GCC 4.6, and will remove it next release. To restore previous behavior, either add NDK_TOOLCHAIN_VERSION=4.6 to ndk-build, or add --toolchain=arm-linux-androideabi-4.6 when executing make-standalone-toolchain.sh on the command line. GCC 4.9 remains the default for 64-bit ABIs.
  • Stopped all x86[_64] toolchains from adding -mstackrealign by default. The NDK toolchain assumes a 16-byte stack alignment. The tools and options used by default enforce this rule. A user writing assembly code must make sure to preserve stack alignment, and ensure that other compilers also comply with this rule. (GCC bug 38496)
  • Added Address Sanitizer functionality to Clang 3.5 support to the ARM and x86 ABIs. For more information on this change, see the Address Sanitizer project.
  • Introduced the requirement, starting from API level 21, to use -fPIE -pie when building. In API levels 16 and higher, ndk-build uses PIE when building. This change has a number of implications, which are discussed in Developer Preview Issue 888. These implications do not apply to shared libraries.

And much more ...

Address and Thread Sanitizers in GCC -- Red Hat Developer Blog

A short article about two error-detection features in GCC:

Address and Thread Sanitizers in GCC

by Dodji Seketeli on Red Hat Developer Blog

From the article:

Since their 4.8 version, the C and C++ compilers of the GNU Compiler Collection are equipped with built-in memory and data race errors detectors named Address Sanitizer and Thread Sanitizer.

This article intends to quickly walk you through the highlights of these two interesting tools.

ccache 3.2 released

Version 3.2 of ccache was recently released. It can help you be more productive as "It speeds up recompilation by caching previous compilations and detecting when the same compilation is being done again" (from the official page). The new version that has been released is a feature version which means lots of goodies and new features.

ccache 3.2 released

From the announcement:

  • Added support for configuring ccache via one or several configuration files instead of via environment variables. Environment variables still have priority but are no longer the recommended way of customizing ccache behavior. See the manual for more information.
  • Added support for compiler error/warning messages with color.
  • Made creation of temporary directories and cache directories smarter to avoid unnecessary stat calls.
  • Improved efficiency of the algorithm that scans for __DATE__ and __TIME__ tokens in the hashed source code.
  • Added support for several binaries (separated by space) in CCACHE_PREFIX.
  • The -c option is no longer passed to the preprocessor. This fixes problems with clang and Solaris’s C++ compiler.
  • ccache no longer passes preprocessor options like -D and -I to the compiler when compiling preprocessed output. This fixes warnings emitted by clang.

And much more ...

 

Overload 124 is now available

overload-124.PNGOverload 124 is now available. It contains the following C++-related articles, and more:

 

Overload 124

Designing Observers in C++11

The observer pattern is over two decades old. Alan Griffiths fits a venerable design pattern into a contemporary context.

Order Notation in Practice

What does complexity measurement mean? Roger Orr reminds us of the academic definition and looks at some real life situations... std::sort is faster than qsort which can come as a surprise to those who assume C is always faster than C++.

Common reasons of using namespaces in C++ projects -- CoderGears Team

CoderGears team draws some conclusions on how namespaces are used in C++ projects:

Common reasons of using namespaces in C++ projects

by CodeGears Team

From the article:

Namespaces in C++ are most often used to avoid naming collisions. Although namespaces are used extensively in recent C++ code, most older code does not use this facility. After exploring the source code of many C++ projects, here are some common reasons of using the namespaces in these projects...

A gotcha with Boost.Optional --Andrzej Krzemieński

Have you used the Boost.Optional library? There is one thing you might need to keep an eye on as explained by Andrzej.

  A gotcha with Optional

  by Andrzej Krzemieński

From the article:

This post is about one gotcha in Boost.Optional library. When starting to use it, you might get the impression that when you try to put optional<T> where T is expected, you will get a compile-time error. In most of the cases it is exactly so, but sometimes you may get really surprised...

Quick Q: How do I add elements to a 2D vector of ints?--StackOverflow

Quick A: Index into the desired sub-vector and call push_back.

Recently on SO:

Inserting elements into 2D vector

So I'm creating a class that implements an adjacency list. Currently in my class definition I initialized two vectors:

vector<vector<int>> adjList;
vector<int> neighbors;

and I declared two functions that I plan to use to make it:

bool constructAdjList();
bool insertIntoAdjList(int, int);

It's getting difficult wrapping my head around 2D vectors. I understand that it is essentially a vector of vectors, but I'm confused about how to insert a new value into one of the "subvectors". For example, I am able to create an adjacency list in createAdjList that is empty with the following loop:

for (int i = 0; i < numOfValues; i++){
    neighbors.push_back(0);
    adjList.push_back(neighbors);
    neighbors.clear();
}

But how can I say, push_back the value 5 to the 4th vector in adjList, which would be represented in my insertIntoAdjList function as

insertIntoAdjList(4, 5);

I know I can access a specific value in a 2D vector by saying adjList[4][1], but how can I push one onto it?

Thanks!

Quick Q: Does std::vector resize automatically when inserting new elements?--StackOverflow

Quick A: Yes.

Recently on SO:

Do Vectors resize automatically?

I am very sorry that I am asking such a beginner question but I am finding contradictory information online. I would ask at University but it is out until February next year.

Do Vectors resize automatically? Or do you need to check the current size periodically and resize when you need more room. It looks to be resizing for me automatically but I'm not sure if that is a feature or the compiler waving a magic wand.