lkml.org 
[lkml]   [2001]   [Sep]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectType checking MIN with standard interface

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;
}

-----------------------------------------------------------------------------
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:02    [W:0.034 / U:0.004 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site