Anti-nuisance lawsuit warning: The purpose of these notes is to remind me, Zoegond, of stuff or to help me work stuff out. They may contain mistakes.

Quick

  • ($a, $b....) = unpack("A2A7...", $packed)
  • push( array, list )

Tuesday, June 28, 2011

C++ since 1996

Ongoing notes about how C++ has changed since I last used it.

Namespaces


'using' for namespaces, can specify a whole namespace or just one name from it. Don't have to use using, can use explicit scope prefixes eg

std::string s;

(NB with mingw 'using std' will cause loads of errors with eg '#include vector'. The scope prefix way works fine though. May be some fix for this involving editing stl_user_config.h)

Executable size


If you do use any of the standard libraries, be prepared for a gigantic executable. 100K for declaring a 'string', 125K if you want to assign it too, 500K to print it out via iostream. In a way though this is a good thing as it's effectively offering you a higher level language - if you want a small executable you can still write C++, just not use any standard includes. stdio.h still works if you need it and the executable size is still only 20K for a minimal example.

(NB the huge executable thing is not there under Linux, the minimal executable is about 7K whichever way you do it).

(Further NB that even under Windows most of the hugeness is due to iostream. Using cstdio (ie stdio.h) instead cuts that 500K down to 130K.)


No finally


C++ has no finally in its exception handling. If you need to release a resource, make its pointer a public member of a local class (local classes are allowed, apparently) and have the class's destructor free the resource. Eg

class Allocs {
public: char *stem;
~Allocs() { delete stem; }
};
Allocs m;

Followers

Blog Archive