Nathan's Lucubrations

25 03 2011

Fri, 25 Mar 2011

Really cool Debian package: binfmtc

This is something I really keep meaning to tell people about: binfmtc. It may not seem like much, but being able to rapidly iterate a prototype, or just test something to learn about how it works is tremendously powerful. I think it was Brooks' in "Mythical Man-Month" who said that interactive programming should not be overlooked as a very powerful tool.

The real nifty thing, though, are the included example utilities, realcsh.c and realksh.c. No, those aren't replacements for Korn shell and C shell. They are actual scripting shells for C and, wait for it - kernel mode scripting! That's right, with root privileges, you too can be mucking about in kernel space, right on your very own commandline! Dangerous but awesome!

Just to give you and idea, here's my Template.cc I've been using over the past months to work on exercises from Thinking in C++, Volume 2:

/*BINFMTCXX:
 */

// -*- Mode: C++ -*-
// Copyright (C) 2011 Nathan Paul Simons (C2T9uE-code@hardcorehackers.com)
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// Alternatively, the GPL can be found at
// http://www.gnu.org/copyleft/gpl.html

// For copy().
#include <algorithm>

// For std::cout and std::endl.
#include <iostream>

// For std::ostream_iterator<>.
#include <iterator>

// For EXIT_SUCCESS.
#include <cstdlib>

int main(int argc,
         char* argv[])
{
  using namespace std;

  if(argc < 1)
    return EXIT_FAILURE;

  copy(argv,
       argv + argc,
       ostream_iterator<char*>(cout, "\n"));

  std::cout << "Hello, world!" << std::endl;

  return EXIT_SUCCESS;
}

Just 'M-x insert-buffer RET Template.cc' and you're good to start hacking! You can add compiler flags either to the line starting with /*BINFMTCXX: or put them in the environment variable BINFMTCXX_GXX_OPTS. I prefer the latter, as I use quite a few, which I initially picked by running 'g++ --help=warnings | awk '{print $1}' | sort | egrep "\-W"' on the commandline and weeding out the ones that didn't apply to C++ from there, then additionally eliminating flags that were more annoying than helpful (such as -Wabi, -Waggregate-return, -Winline, -Wpadded, and -Wunreachable-code). You can also link to external libraries this way, but it doesn't always work cleanly for linking to external object code (.o files); your safest bet is relying on libraries that only require header includes, or just including implementation source files (.cc files).

posted at: 00:12 | path: | permanent link to this entry

powered by blosxom