Sunday, August 23, 2009

mysql-embedded

Well, I was looking at sqlite last week. But while doing a yum update I found this rpm package. "mysql-embedded". On doing a rpm -qi, it told me that this is a C interface to mysql that can directly be embedded in your application. I haven't tried it yet. But I am sure its going to be interesting. The package has only one shared library. However the size is ~7.5M. If I happen to use it, will post again here.

Sunday, August 9, 2009

Presentation database

My wife asked me for this simple application which will store and display the details of daily presentations that they do at their department. Well, I can create a simple text interface in C and it will not even take me an hour to complete. But, there are constraints.

1. This has to be a graphical application
2. This has to be usable by non-geeks
3. This has to run on MS Windows!
4. This has to be searchable

I was thinking of many things. Till requirement 3, I can manage with some vague wiki/CMS software. (Say twiki with table plugin). However, that is surely not going to be user friendly. I have been recently been working on Java. But, my Java skills are not that good. Besides Java will be a overkill for such a simple application.

It is at this point I noticed sqlite. (Well, this has pained me through firefox cookie database once before this). When I read about it, I found that it has a good tcl API. So, thats it! sqlite+tcl/tk!

I have just started. Will keep updating this space as and when I progress.

Saturday, August 8, 2009

__VA__ARGS__

How to create a macro which takes variable number of arguments?

I had to do this as I wanted to replace a printf with a common debug function that can be turned on or off in the runtime. Besides, I wanted to print local variables from that function. The simplest way was to define a macro that will replace the printf.

However, printf takes variable number of arguments. How do I handle that in a macro? The answer was __VA_ARGS__. Using this, you can replace (more or less) any printf with something like what is shown below.


#define DBG_PRN(x,...) do {\
if ( is_debug_on() )\
{\
printf(x,__VA_ARGS__);\
}\
}while(0);


The downside is, you need to have minimum of two arguments for printfs. If you do not have minimum two arguments, you will get a compilation error.I solve this by providing a dummy variable.

The gcc way of doing this is different. That depends on the the pre-processor operator ## to achieve this. This method will help you solve the empty argument issue.