Hi, I came by a really weird macro code in linux/jbd.h<http://lxr.free-electrons.com/source/include/linux/jbd.h#L1029>which is BUFFER_TRACE(bh,info) do{} while(0). Please explain the necessity of this. -- With Regards Dibyayan Chakraborty
On 23 June 2013 17:18, Dibyayan Chakraborty <dib.coolguy@gmail.com> wrote:
Hi, I came by a really weird macro code in linux/jbd.h which is
BUFFER_TRACE(bh,info) do{} while(0).
Please explain the necessity of this.
I'm not familiar with that specific code, but it looks like a "no op" macro. Maybe the definition is the to ensure backwards or forward compatibility for the code that calls the macro , but now it doesn't do anything. For the reason why there is a while(0), instead of just no code there, take a look at this: http://kernelnewbies.org/FAQ/DoWhile0 Hope this helps.
On Tue, 25 Jun 2013 09:56:43 +0300, Alexandru Juncu said:
On 23 June 2013 17:18, Dibyayan Chakraborty <dib.coolguy@gmail.com> wrote:
Hi, I came by a really weird macro code in linux/jbd.h which is
BUFFER_TRACE(bh,info) do{} while(0).
Please explain the necessity of this.
I'm not familiar with that specific code, but it looks like a "no op" macro. Maybe the definition is the to ensure backwards or forward compatibility for the code that calls the macro , but now it doesn't do anything.
Actually, the kernel doesn't use this for forward/backward compatability that much. It's mostly used for handling optional code - you'll often find stuff like this in .h files: #ifdef CONFIG_FOOBAR_DEBUG #define MY_TRACE printk(lots-o-oarams-here) #else #define MY_TRACE() do{} while(0) #endif That way, the main .c file will compile cleanly whether or not the CONFIG option is selected.
participants (3)
-
Alexandru Juncu -
Dibyayan Chakraborty -
Valdis.Kletnieks@vt.edu