piątek, 18 kwietnia 2014

How it's made: C++ compilers - slides


As I recently wrote, yesterday I conducted a lecture about internals of C++ compilers for C++ Wrocław User Group. I'd like to share the slides with the world. You can access them here.

Unfortunately, audio mixer settings were broken, so the screencast is not published.





środa, 16 kwietnia 2014

Yet another interesting dark corner of C++

Dear C++ experts ;>:

Is following code correct or is it ill-formed?

typedef vector<int> Integers;

Surely, it isn't. What about following?

vector<int> typedef Integers;

Is it well formed? It turns out that it is. I've found this information here. I decided to dig in a little.
It seems that defining multiple type aliases for particular type is fine when the type is same for all aliases. For example, following snippet is not ill-formed:

typedef vector<int> Integers;
vector<int> typedef Integers;

This is suspicious, though. This is nearly the same what is used in Standard Template Library (STL), e.g. in initializer_list:

class initializer_list {   
public:
    typedef _E    value_type;
    typedef const _E&    reference;
    typedef const _E&    const_reference;

Here we can see that initializer_list defines reference and const_reference type aliases, but they actually are of same type. Actually this happened earlier in std::set, where both iterator and const_iterator are constant (otherwise a programmer could interfere on std::set internals).

The question is - in how many C++ places we can expect similar (unfamiliar) syntactical opportunities? Please share your ideas in comments. From my experience I can add the following.

struct S {
    void static const meth(int const) {}
};

The first interesting thing is that the static keyword occurs in quite weird place. The second thing, far more interesting is the const void type. There's no point to have such a type in C++ language. Or is it?



poniedziałek, 7 kwietnia 2014

C++11 quirk: Default c-tor & cv-qualified instances

Recently I found an interesting C++11 quirk.

http://jaredgrubb.blogspot.com/2013/05/c11-quirks-in-defaulted-functions.html

According to answers from the stack overflow it comes out that POD objects cannot be used with default constructors if you wish to create const instance of them. And it makes sense, as the const object cannot be changed in future.

The funny part is when you use `= default` outside of class body everything's fine.

Interestingly Clang compiler is again closer to the standard than gcc. It doesn't compile following code, whereas gcc does.

struct A { A() = default; }
int main(int, char) { const A a; }

Thanks to Jonathan Wakely it turned out that Clang behavior is the proper one. The C++ standard states:

"A special member function is user-provided if it is user-declared and not explicitly defaulted on its first declaration. A user-provided explicitly-defaulted function (i.e., explicitly defaulted after its first declaration) is defined at the point where it is explicitly defaulted; if such a function is implicitly defined as deleted, the program is ill-formed." [N3242, 8.4.2/4]


niedziela, 6 kwietnia 2014

How it's made: C++ compilers - Wrocław C++ User Group

Please feel invited to my presentation on C++ compilers' internals.

Place: University of Wrocław
Time: 17.04.2014

You can find more information here (PL).

sobota, 5 kwietnia 2014

Measuring C++ code quality - tools and techniques

My another article was published in last "Programista" journal. It is about tools and techniques that help measuring C++ software quality. It covers many practical aspects like code coverage, cyclomatic complexity, dependencies, etc.

Cover page