poniedziałek, 7 grudnia 2015

C++11 and initialization

Uniform initialization in C++11 can be tricky.

Invocations mean something completely different and also give different results:

std::vector<int> v(1); // "normal" constructor invocation with (int) param - creates vector<int> with 1 element initialized to default value (i.e. 0)
std::vector<int> v{1}; // invocation of constructor with initializer_list<> param - content of initializer_list is copied into vector (i.e. one value of 1)


Following invocations also mean something completely different and give different results:

std::vector<int> v(1, 1); // "normal" constructor invocation with (int,int) params - creates vector<int> with 1 element initialized to specified value value (i.e. 1)
std::vector<int> v{1, 1}; // invocation of constructor with initializer_list<> param - content of initializer_list is copied into vector (i.e. two values of 1)


But following mean something completely different but give same results:

std::vector<int> v(2, 2); // "normal" constructor invocation with (int,int) params - creates vector<int> with 2 elements initialized to specified value value (i.e. 2)
std::vector<int> v{2, 2}; // invocation of constructor with initializer_list<> param - content of initializer_list is copied into vector (i.e. two values of 2)


Note that following will not compile:

std::vector<int> v(1, 1, 1); // no such "normal" constructor

whereas following is completely fine C++11 statement:

std::vector<int> v{1, 1, 1}; // invocation of constructor with initializer_list<> param - content of initializer_list is copied into vector (i.e. three values of 1)


Also note what is perhaps even more surprising that when container value type cannot be initialized from values in the list (no such conversion), then following construction will invoke "normal" constructor:

std::vector<std::string> v{1}; // same as - std::vector<std::string> v(1);


To avoid such behavior assign can be used in initialization (this is still construction, not assignment):

std::vector<std::string> v = {1}; // this will fail to compile
std::vector<int> v = {1}; // this will invoke initializer_list<> constructor as for std::vector<int> v{1};


There is even more about uniform initialization, especially using "auto" keyword - please check e.g. "Effective Modern C++" by Scott Meyers.
Also please check stackoverflow.

poniedziałek, 9 listopada 2015

Thread-safe Catch

Catch test framework is nice, but not thread-safe - see https://github.com/philsquared/Catch/issues/99

There is thread-safe fork of Catch https://github.com/ned14/Catch-ThreadSafe
At the time of writing this original Catch is 1.2.1 whilst thread-safe fork 1.1

piątek, 6 listopada 2015

With or without you (exceptions)

To exception, or not to exception, that is the question.
What about cyclomatic complexity argument? E.g. http://programmers.stackexchange.com/questions/219872

piątek, 28 sierpnia 2015

upgradeable RW-locks - no, no

Never to be forgotten - upgradeable RW-locks always lead to deadlock.
I.e. when reader upgrades to writer without first leaving read lock, then other tread doing same lead to deadlock - no one moves back - deadlock.
Therefore:
- do not think on upgradeable RW-locks,
- if do so, then try-upgrade() function might be good approach, or
- deadlock detection, or
- 3rd user type - beside reader and writer - upgreadeableReader (like EnterUpgradeableReadLock from .NET). There can be only one upgreadeableReader (mutually exclusive). Normal readers cannot upgrade, therefore it is certain that only one user-reader will try to upgrade.

Redirect tcp to console (file) with awk

Sometimes useful, esp. when redirecting local tcp process output to console (file):

BEGIN {
NetService = "/inet/tcp/0/localhost/finger"
print "name" |& NetService
while ((NetService |& getline) > 0)
print $0
close(NetService)
}

More info @http://www.gnu.org/software/gawk/manual/gawkinet/gawkinet.html#Making-Connections

QNX specific commands

List of interesting (subjective) QNX-specific commands
  • on - usually used for 2 reasons: start new process with specified priority and/or start new process on specific node (it makes possible to start process on different processor/system running QNX - working qnet is required - see Asymmetric multiprocessing (AMP))
  • pidin - process list, frequently more useful than ps, top (e.g. options "-f A", "-f n","threads", "memory", "fds")
  • coreinfo - allows for preliminary corefiles analysis directly on target without using gdb (note that in QNX coredumps are produced by dumper)
  • use - info about specific command (e.g. "use devf-generic", "use -i devf-generic" - for build version)
  • sendnto e.g. "sendnto -d /dev/ttyUSB1 qnx-ifs" (together with "cat /dev/ttyUSB1" and "echo 's' >/dev/ttyUSB1")

piątek, 20 lutego 2015

Virtualbox, linux, remote desktop, NAT

Enable NAT in VB machine network settings, set port mapping e.g. SOME_HOST_PORT->3389 (remote desktop) and SOME_HOST_PORT->22(ssh)
To start VB as windows service use vboxvmservice.

References
http://vboxvmservice.sourceforge.net/
http://support.microsoft.com/kb/304304/
http://code.google.com/p/phpvirtualbox/
http://code.google.com/p/virtualboxservice/
http://www.techques.com/question/2-188105/Virtualbox-Start-VM-Headless-on-Windows
http://www2.ece.ohio-state.edu/computing/rdpssh.html
https://help.ubuntu.com/community/SSH/OpenSSH/PortForwarding

poniedziałek, 9 lutego 2015

non-intrusive compile-time types registration



Note - above does not work with VS compilers.
Generally this approach should be avoided, but nice to know:)

sobota, 31 stycznia 2015

What's nice there

eTrice provides an implementation of the ROOM (Real-Time Object-Oriented Modeling) modeling language together with editors, code generators for Java, C++ and C code and exemplary target middleware.
The model is defined in textual form (Xtext) with graphical editors (Graphiti) for the structural and behavioral (i.e. state machine) parts.
http://www.eclipse.org/etrice/

Trace Compass is a Java tool for viewing and analyzing any type of logs or traces. Its goal is to provide views, graphs, metrics, etc. to help extract useful information from traces, in a way that is more user-friendly and informative than huge text dumps.
http://projects.eclipse.org/projects/tools.tracecompass


https://developers.google.com/web/fundamentals/


FlatBuffers is a serialization library for games and other memory constrained apps.
https://github.com/google/flatbuffers

Protocol Buffers - Google's data interchange format.
https://github.com/google/protobuf

The C++ Network Library Project -- header-only, cross-platform, standards compliant networking library.
https://github.com/google/cpp-netlib

A fast compressor/decompressor.
https://github.com/google/snappy

Brotli compression format.
https://github.com/google/brotli

Fruit is a dependency injection framework for C++.
https://github.com/google/fruit

RE2 is a fast, safe, thread-friendly alternative to backtracking regular expression engines like those used in PCRE, Perl, and Python. It is a C++ library.
https://github.com/google/re2

redgrep is a grep based on regular expression derivatives.
https://github.com/google/redgrep

Gumbo is an implementation of the HTML5 parsing algorithm implemented as a pure C99 library with no outside dependencies.
https://github.com/google/gumbo-parser

lmctfy is the open source version of Google’s container stack, which provides Linux application containers.
https://github.com/google/lmctfy

Lovefield is a relational query engine built on top of IndexedDB. It provides SQL-like syntax and works cross-browser (currently supporting Chrome 37+, Firefox 31+, and IE 10+).
https://github.com/google/lovefield

codefmt is a utility for syntax-aware code formatting. codefmt relies on codefmtlib for registration and management of formatting plugins.
https://github.com/google/vim-codefmt

Cppcheck is a static analysis tool for C/C++ code. Unlike C/C++ compilers and many other analysis tools it does not detect syntax errors in the code. Cppcheck primarily detects the types of bugs that the compilers normally do not detect. The goal is to detect only real errors in the code (i.e. have zero false positives).
http://cppcheck.sourceforge.net/

pugixml is a light-weight C++ XML processing library (it has XPath 1.0 implementation for complex data-driven tree queries).
http://pugixml.org/

Modern, powerful open source C++ class libraries for building network- and internet-based applications
http://pocoproject.org/

Multi-paradigm automated test framework for C++ and Objective-C (and, maybe, C). It is implemented entirely in a set of header files, but is packaged up as a single header for extra convenience.
https://github.com/philsquared/Catch

Some interesting C++ articles e.g. small size containers optimization using custom allocator
http://howardhinnant.github.io/

Gold linker
https://en.wikipedia.org/wiki/Gold_(linker)

Warp preprocessor
https://github.com/facebook/warp

LevelDB is a fast key-value storage library written at Google that provides an ordered mapping from string keys to string values.
https://github.com/google/leveldb

Kyoto Cabinet is a library of routines for managing a database.
http://fallabs.com/kyotocabinet/

UnQLite is a in-process software library which implements a self-contained, serverless, zero-configuration, transactional NoSQL database engine.
http://unqlite.org/

A Fast Key-Value Storage Engine Based on Hierarchical B+-Tree Trie
https://github.com/couchbase/forestdb

LMDB is an ultra-fast, ultra-compact, crash-proof key-value embedded data store
http://symas.com/mdb/

SQLite4 (with LSM - embedded database library for key-value data)
https://sqlite.org/src4/doc/trunk/www/index.wiki

FineDB.org - A high-performance noSQL database
http://www.finedb.org/

High performance JSON manipulation library
https://github.com/couchbase/subjson

Highly portable C system library
https://github.com/saprykin/plibsys

Memory optimal Small String Optimization implementation for C++
https://github.com/elliotgoodrich/SSO-23

c2xml is a tool that generates a XML representation of pre-processed ANSI C source code
http://c2xml.sourceforge.net/

Fake Function Framework (fff)
https://github.com/meekrosoft/fff

niedziela, 18 stycznia 2015

Problem with Bluetooth in Dell Precision M4600
No connection neither from Linux nor Windows 7. The point is everything worked properly some time ago. Now Bluetooth seems to work and find devices, but after connection attempt it is broken instantly.
'hciconfig' shows device properly and from 'bluetoothctl', command 'paired-devices' shows devices properly.
Then using 'connect <dev>' everything worked again.