Saturday, December 8, 2007

emacs: how-many

Discovered another emacs command yesterday:

how-many

Returns the count of a regex following the point (cursor position).

For example

M-x how-many
\b\w

returns a word count from point to the end of the buffer.

Nice.

Friday, December 7, 2007

C: Passing on variadic function arguments to another function

I needed to do this today, and it took me a while to google it, so here is complete sample showing how it's done:


// How to pass a variadic argument list to another function
// Justin

#include "iostream"
#include "stdarg.h"

using namespace std;

void debugMessageHelper(char *buffer, const char* format, va_list arglist)
{
vsprintf(buffer, format, arglist);
}

void debugMessage(char *buffer, const char* format, ...)
{
va_list arg;
va_start(arg, format);

debugMessageHelper(buffer, format, arg);

va_end(arg);
}

int main(int argc, char *argv[])
{
char testBuffer[128];

debugMessage(testBuffer, "hello %s %u %-04.2f", "world", 21 33.122f);

cout << "\'" << testBuffer << "\'" << endl;

}