Friday, July 22, 2011

'format' attribute in gcc

We can check the format of a function against the set of arguments using 'format' attribute. This is is very much useful when we write our own logger function. The format attributes check for the format of a particular function against format of predefined function. The index of format and the variable arguments in the function have to be passed into the attribute.

Ex: void log_inline(const char* format, ...) __attribute__((format(printf,1,2)));

The format of log_inline is checked against the printf function. The format that has to be checked is the first argument of log_inline, while arguments start with second position of log_inline. This is specified as (1,2) in format attribute.

There is an example program:


void log_inline(const char* format, ...) __attribute__((format(printf,1,2)));

void log_inline(const char* format, ...)
va_list args;
va_start(args, format);
vprintf(format, args);

int main()
log_inline("%s\n", "SOMETHING");
log_inline("%s\n",1); //Generates warning message

We need to compile with -Wall option of gcc to identify the warning.

Note that without attribute in function declaration, warning is not produced.

Saturday, July 2, 2011

World IPv6 day.

8th June 2011 was world ipv6 day. If you refer the link "", it says many of the companies (including linux kernel site) did switch to ipv6 stack to have global scale trial. If you refer the resource section, some countries have their own ipv6 day. Hope India will also have one in future. The event passed on without making any news at-least to me!! Here is the logo

WORLD IPV6 DAY is 8 June 2011 – The Future is Forever

May be every year this event happens however this is first time I am noticing though; roughly a month after event passed off!!