From: Bill Pringlemeir <bpringle@sympatico.ca>
To: David Woodhouse <dwmw2@infradead.org>
Cc: Alex Bligh - linux-kernel <linux-kernel@alex.org.uk>,
Tim Walberg <twalberg@mindspring.com>,
"J. Imlay" <jimlay@u.washington.edu>,
linux-kernel@vger.kernel.org
Subject: Re: macro conflict
Date: 24 Aug 2001 14:12:35 -0400 [thread overview]
Message-ID: <m24rqxfht8.fsf@sympatico.ca> (raw)
In-Reply-To: <2606707256.998677533@[10.132.112.53]> <14764.998658214@redhat.com> <6242.998674456@redhat.com>
In-Reply-To: David Woodhouse's message of "Fri, 24 Aug 2001 18:34:16 +0100"
>>>>> "David" == David Woodhouse <dwmw2@infradead.org> writes:
> printf ("%d %d\n", min(foo, 10), min (bar, 20)); }
David> Well, ideally both of them would BUG() and the user would have
David> to explicitly cast one (or both) of the arguments so the types
David> match. But as Keith pointed out, it won't work.
Why would both BUG? 20 is a signed integer and bar _could be_ a signed
char. This is fine. As a matter of fact, both constants are positive
and fit in the range so I don't really think this is a bug in either
case. I guess the constants should be written as 10U and 20U. There
are other problems as the code without a specifically type char will
have bugs on the ARM (and others with different sign default). I
don't think that the casting handles this well either.
I did a little more beautification. Gcc does warn if you compare a
pointer to an integral type. Do you need more? The bug_paste macro
would pollute the name-space, but it is nice to see where things go
wrong.
fwiw,
Bill Pringlemeir.
[test.c]
#define bug_paste_chain(a,b) a##b
#define bug_paste(a) bug_paste_chain(BUG_AT_LINE_,a)
#define min(x,y) \
\
({extern void bug_paste(__LINE__) (void); \
typeof(x) _x = 0; typeof(y) _y = 0; \
if ((_x-1>0 && _y-1<0) || (_x-1<0 && _y-1>0)) \
bug_paste(__LINE__)(); \
_x = (x), _y = (y); (_x>_y)?_y:_x; \
})
#include <stdio.h>
int main(int argc, char *argv[])
{
signed char cx = 1, cy = 2;
signed short sx = 1, sy = 2;
signed int ix = 1, iy = 2;
signed long lx = 1, ly = 2;
unsigned char Cx = 1, Cy = 2;
unsigned short Sx = 1, Sy = 2;
unsigned int Ix = 1, Iy = 2;
unsigned long Lx = 1, Ly = 2;
cx = min(cx,cy); Cx = min(Cy,Cx); sx = min(sx,sy);
Sx = min(Sx,Sy); ix = min(iy,ix); Ix = min(Iy,Ix);
lx = min(ly,ly); Lx = min(Lx,Ly);
/* No warning. */
/* Lx = (typeof(Lx))min(Lx,&Ly); */
printf("%d %d %hd %hd %d %d %ld %ld\n", cx, Cx,
sx,Sx,ix,Ix,lx,Lx);
cx = -1; Cx = 0;
cx = min(cx,cy); sx = min(cx,sy);
ix = min(cx,ix); lx = min(cx,ly);
Cx = min(Cx,Cx); Sx = min(Cx,Sy);
Ix = min(Ly,Ix); Lx = min(Ix,Ly);
/* correctly gives warning! Promotion to int before compare. */
/* Ix = min(Cy,Ix); Lx = min(Cx,Ly); */
printf("%d %d %hd %hd %d %d %ld %ld\n", cx, Cx,
sx,Sx,ix,Ix,lx,Lx);
/* BUG? printf ("%d\n", min(Iy, 10)); */
printf ("%d\n", min(cx, 20));
return 0;
}
prev parent reply other threads:[~2001-08-24 18:17 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-08-23 19:03 macro conflict J. Imlay
2001-08-23 19:21 ` Alan Cox
2001-08-23 19:34 ` Tim Walberg
2001-08-23 20:01 ` Alan Cox
2001-08-23 20:02 ` raybry
2001-08-23 20:16 ` Magnus Naeslund(f)
2001-08-23 20:27 ` Alan Cox
2001-08-23 20:29 ` Magnus Naeslund(f)
2001-08-23 23:18 ` Andrew Cannon
2001-08-23 23:37 ` Magnus Naeslund(f)
2001-08-23 23:35 ` Roman Zippel
2001-08-24 1:42 ` Camiel Vanderhoeven
2001-08-24 13:03 ` David Woodhouse
2001-08-24 13:15 ` Keith Owens
2001-08-24 13:17 ` David Woodhouse
2001-08-24 14:20 ` Bill Pringlemeir
2001-08-24 21:17 ` Roman Zippel
2001-08-24 13:34 ` Richard B. Johnson
2001-08-24 18:20 ` David Wagner
2001-08-24 17:25 ` Alex Bligh - linux-kernel
2001-08-24 17:34 ` David Woodhouse
2001-08-24 18:12 ` Bill Pringlemeir [this message]
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=m24rqxfht8.fsf@sympatico.ca \
--to=bpringle@sympatico.ca \
--cc=dwmw2@infradead.org \
--cc=jimlay@u.washington.edu \
--cc=linux-kernel@alex.org.uk \
--cc=linux-kernel@vger.kernel.org \
--cc=twalberg@mindspring.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