LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Sri Ram Vemulpali <sri.ram.gmu06@gmail.com>
To: Manish Katiyar <mkatiyar@gmail.com>
Cc: Kernel-newbies <kernelnewbies@nl.linux.org>,
	linux-kernel-mail <linux-kernel@vger.kernel.org>
Subject: Re: typecheck code
Date: Mon, 31 Jan 2011 15:23:33 -0500	[thread overview]
Message-ID: <AANLkTimCHUmEJ7wFbSF80Fz3b-nyr_PGqbJ5iq4uNSGF@mail.gmail.com> (raw)
In-Reply-To: <AANLkTimTQxDCJ004VOFCdo3rz01tHsj9R4Ce1OGb75sH@mail.gmail.com>

Thanks for all explanation. It really helped to understand.

Sri

On Mon, Jan 31, 2011 at 1:03 PM, Manish Katiyar <mkatiyar@gmail.com> wrote:
> On Mon, Jan 31, 2011 at 9:03 AM, Sri Ram Vemulpali
> <sri.ram.gmu06@gmail.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
>
> Infact I think it will never return 1, since the addresses of __dummy1
> and __dummy2 have to be different (off by 4 or 8). As pointed out it
> is the next line that always returns 1. The purpose of this line is to
> throw away warnings like "Incompatible pointer comparison" or
> something like that (haven't tried :-)) incase there is a mismatch.
>
> --
> Thanks -
> Manish
>



-- 
Regards,
Sri.

  reply	other threads:[~2011-01-31 20:23 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-31 17:03 Sri Ram Vemulpali
2011-01-31 17:20 ` Jamie Iles
2011-01-31 17:22 ` Geert Uytterhoeven
2011-01-31 17:44 ` Rajat Sharma
2011-01-31 18:03 ` Manish Katiyar
2011-01-31 20:23   ` Sri Ram Vemulpali [this message]
2011-01-31 20:26 ` Dave Hylands
2011-01-31 21:42   ` julie Sullivan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AANLkTimCHUmEJ7wFbSF80Fz3b-nyr_PGqbJ5iq4uNSGF@mail.gmail.com \
    --to=sri.ram.gmu06@gmail.com \
    --cc=kernelnewbies@nl.linux.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mkatiyar@gmail.com \
    --subject='Re: typecheck code' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).