[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <AANLkTimgTCdJfyKcyrpM-VgWtNCFonu2rvca+pkc+ebh@mail.gmail.com>
Date: Mon, 31 Jan 2011 12:26:15 -0800
From: Dave Hylands <dhylands@...il.com>
To: Sri Ram Vemulpali <sri.ram.gmu06@...il.com>
Cc: Kernel-newbies <kernelnewbies@...linux.org>,
linux-kernel-mail <linux-kernel@...r.kernel.org>
Subject: Re: typecheck code
Hi Sri,
On Mon, Jan 31, 2011 at 9:03 AM, Sri Ram Vemulpali
<sri.ram.gmu06@...il.com> wrote:
> Hi all,
>
> /*
> * Check at compile time that something is of a particular type.
> * Always evaluates to 1 so you may use it easily in comparisons.
> */
> #define typecheck(type,x) \
> ({ type __dummy; \
> typeof(x) __dummy2; \
> (void)(&__dummy == &__dummy2); \
> 1; \
> })
>
> #define typecheck_fn(type,function) \
> ({ typeof(type) __tmp = function; \
> (void)__tmp; \
> })
>
> Can anyone help me, explain the above code typecheck. How does
> (void)(&__dummy == &__dummy2) evaluates to 1
>
> I appreciate any explain.
If dummy and dummy2 are of different types, then when you try and do a
pointer comparison (&dummy == &dummy2) it will produce a compiler
warning/error.
The actual comparison will always fail, but it doesn't matter since
the results aren't used.
typecheck always returns 1.
Dave Hylands
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists