mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Morten Welinder <terra@diku.dk>
To: linux-kernel@vger.kernel.org, torvalds@transmeta.com
Subject: Type checking MIN with standard interface
Date: 6 Sep 2001 19:28:15 -0000	[thread overview]
Message-ID: <20010906192815.28608.qmail@ntyr.diku.dk> (raw)


All the silent-cast properties of integer types do not apply to
pointers.  Therefore...

-----------------------------------------------------------------------------

cub:~> gcc -O2 -Wall min.c
min.c: In function `main':
min.c:19: warning: comparison of distinct pointer types lacks a cast


cub:~> gcc -O2 -Wall kernel-source.c 2>&1 | \
        grep "comparison of distinct pointer types lacks a cast" | \
        find-and-shoot-programmer

:-)

Morten


-----------------------------------------------------------------------------

#include <stdio.h>

#define MIN(x,y)                                \
  ({ const typeof(x) _x = x;                    \
     const typeof(y) _y = y;                    \
                                                \
     (void) (&_x == &_y);                       \
                                                \
     _x < _y ? _x : _y;                         \
  })

int
main ()
{
  /* Good: */
  printf ("%d\n", MIN((signed)1, (signed)1));

  /* Bad: */
  printf ("%d\n", MIN((signed)1, (unsigned)1));

  return 0;
}

-----------------------------------------------------------------------------

             reply	other threads:[~2001-09-06 19:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-09-06 19:28 Morten Welinder [this message]
2001-09-07 22:41 ` Linus Torvalds

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=20010906192815.28608.qmail@ntyr.diku.dk \
    --to=terra@diku.dk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@transmeta.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®