Archive for February, 2007

C/C++ – _M_underflow_common

February 13, 2007

When you define you own character traits (e.g., ignorecase_traits – to ignore the case when comparing strings) you might run into the following link error:

In function `std::basic_filebuf<char, ignorecase_traits>::uflow()'::
undefined reference to `std::basic_filebuf<char, ignorecase_traits>::
_M_underflow_common(bool)'

The solution is to add the following to one of your CC/CPP files:

struct cGet_M_underflow_common : std::basic_filebuf<char> {
  int_type mGet_M_underflow_common(bool b) {
    return _M_underflow_common(b);
  };
};

icfielbuf::int_type icfielbuf::_M_underflow_common(bool bump) {
  return reinterpret_cast<cGet_M_underflow_common *>(this)->
    mGet_M_underflow_common(bump);
};

Emacs – change case

February 6, 2007

In order to change the case in Emacs you can use:

M + l to change to lowercase all the letters from the cursor to the end of the word
M + u same meaning, but upercase
M + c same meaning, but capitalizes

C/C++ – binary IO

February 1, 2007

Here is an example of how we can write to and read from files in binary:

Write:
ofstream file(“foo.txt”, ios::out | ios::binary);
unsigned e =101;
file.write(reinterpret_cast<char*>(&e), sizeof(unsigned));

Read:
ifstream file(“foo.txt”, ios::in | ios::binary);
unsigned e;
file.read(reinterpret_cast<char*>(&e), sizeof(unsigned));

More info:
http://courses.cs.vt.edu/~cs2604/spring06/binio.html
http://www.codersource.net/cpp_file_io_binary.html