viernes, 29 de agosto de 2008

miércoles, 13 de agosto de 2008

An useful macro for debugging

Yesterday I've added the debug system for gtranslator, right now it is just a g_message that is showed only if the debug is enabled.
But I wanted some more information and I wanted only with a macro and until some testing and help from some people of #c channel I've got this:
# define DEBUG_PRINT(format, ...) g_debug ("%s:%d (%s)" format, __FILE__, __LINE__, G_STRFUNC, __VA_ARGS__)

That macros prints the file, the line, the name of the func and the test you want. It was quite difficult discover the __VA_ARGS__ so you can do something like DEBUG_PRINT ("Hello %s", "Nacho") and it is going to print all that stuff. I think is good but could be better. You have to pass always the format. To have a behavior like g_print you should create a new func that implements how to get the varg arguments and so.

viernes, 1 de agosto de 2008