HomePage RecentChanges About Projects Computers CPlusPlus11 New Archive


Welcome! This is where I write stuff...

2014-11-22 CPlusPlus11

Digit Separators

When I talked about the binary literals recently I also mentioned digit separators. I thought it was part of C++0x but apparently it is also a new C++1y feature that I have not mentioned yet. Sorry for that. There are so many features so I'm getting confused. ;-) Time to change that then.

Anyway, digit separators is a way to write big numbers so they are easier to read for humans. The apostrophe character is what is used to group or separate digits in a number. It can look like this:

   int decimal = 4'096;
   int binary = 0b0001'0000'0000'0000;
   int hexadecimal = 0x10'00;
   int octal = 0'10'000;
   double x = 1.234'567'890e-19;

Look how the apostrophe neatly groups the digits in the way we are use to see them.

The position of the a apostrophe can however be anywhere in the number. It does not have to be according to the radix or any other normal way numbers are written out there in real life. It can be used in any way you like. The later is probably a bad idea but, who knows, there might be cases where it can be put to good use.

2014-11-17 CPlusPlus11

Binary Literals

One tiny(!?) extension that comes with C++14 is binary literals. You can now write them by prefixing the binary number with 0b. This is a well known syntax from other languages and in fact has been around a while even as a gcc extension. So you might not even recognize this as new feature.

Anyway, it looks like this:

   int b1 = 0b10;
   int b2 = 0B1010;     // Capital B is OK too!

It goes well with digit separators too. You can write:

   int b3 = 0b1010'1010;
   int b4 = 0B010'101'010;

2014-11-12 CPlusPlus11

The deprecated attribute

To mark an entity as deprecated the attribute deprecated is introduced. The idea is to be able to mark things, although they are still working, that their use are being discouraged for some reason. The thought goes to things that will be removed in future releases but it is of course not limited to that.

This is different to most other C++-1y features a compile time only feature. It will produce a warning when the code is compiled. That is it.

The syntax is like this:

int func(int i)

You can even add an explanation to why this function is deprecated and this string will be shown in the warning message by the compiler.

[[deprecated("Don't use this please, we are going to remove this next release or so")]]
int old(int i)

Most entities can be marked as deprecated this way. Here are some examples.

class [[deprecated]] C

class C2
   int func(...

2014-04-19 Rim

Dags för påsk och här är påskrimmet: PåskRimReklampaus

2014-03-05 More on Real Humans

According to people behind the series there were both Javascript, C++ and LISP shown the first season. Since I did not follow the series good enough I missed that and saw only C++ thus making the C++ vs LISP story better than it was. ;-)

2014-01-25 Real Humans are coded in Lisp

The Swedish TV series Real Humans is now on its second season. It is about a time when we have human robots, so called Hubots.

In the series some screens with code are shown briefly. In the first season the code was C++. It had a lot of resemblance with this code. I believe some comments was removed and some other slight changes but the resemblance was striking.

Now in the second season some of the Hubots have gone smarter, more human like. Screens with code are still shown and this time it is appropriately Lisp that is the programming language! The comments are removed as before and some digits replace arguments in one function call but that is all.

See for yourself: The code and a screen dump from the series showing the code

2013-12-25 Rim

Årets julkrim, JulRimSnowden, är åter ett rim på temat avlyssning och övervakning. Ett alltför aktuellt tema och sista ordet eller rimmet är väl inte sagt än.

2013-08-24 Rim

På väg i taxi från Kista till Stockholms city till företagets årliga kräftskiva upptäckte vår ekonomichef att hon glömt skärpet på kontoret. Risk för pösiga byxor var överhängande vilket debatterades och lite olika förslag vad det glömda skärpet kunde användas till kastades fram under resan. Resan avslutade med den här limericken (fritt från minnet och kanske något redigerat ;-)

En blond ekonomichef från Kista
En SM-klubb skulle bevista
Men det blev ingen värk
för hon glömde sitt skärp
Så det smisket fick hon allt mista


Glad midsommar alla. Här kommer årets rim - MidsommarRimMidsommarstång

2013-04-29 CPlusPlus11


Just when you have been starting to wonder when all these nice C++11 features are going to get to the compiler you use in your day job the standardization moves on with C++1y/C++14! For the status of gcc look here. It really seem like the polishing of C++ to make it a modern language has been a positive experience. So now it is time to look into the new C++1y features!