public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Tim Walberg <twalberg@mindspring.com>
To: "J. Imlay" <jimlay@u.washington.edu>
Cc: linux-kernel@vger.kernel.org
Subject: Re: macro conflict
Date: Thu, 23 Aug 2001 14:34:40 -0500	[thread overview]
Message-ID: <20010823143440.G20693@mindspring.com> (raw)
In-Reply-To: <Pine.A41.4.33.0108231150110.64144-100000@dante14.u.washington.edu>
In-Reply-To: <Pine.A41.4.33.0108231150110.64144-100000@dante14.u.washington.edu> from J. Imlay on 08/23/2001 14:03

[-- Attachment #1: Type: text/plain, Size: 2441 bytes --]

There has already been **much** discussion about this, but I think
that the bottom line is that the new version is safer and more
robust than the old version, and thus is not likely to be changed
back.

Consider what happens if someone writes min(++x,y) - the old
version expands to (without some of the extra parens):

	++x < y ? ++x : y

which will increment x twice if the condition ++x < y is true.
There's all kinds of nasty side effects possible with the old
version, including having x > y at the end of the statement, which
definitely violates the semantics of min().

The new version avoids these side effects by only evaluating
the given arguments once (assigning them to temp variables,
which will be optimized away in almost all cases anyway), but
in order to do that, the macro needs to know the variable type,
hence the additional argument. In C++, this can be done using
typename or templates, but the kernel's not written in C++
for a number of very good reasons.

Bottom line, I think the new version of min() and friends is
here to stay and is definitely a positive move. One of the down
sides to that is that a lot of people have a lot of cleaning
up to do.

			tw

On 08/23/2001 12:03 -0700, J. Imlay wrote:
>>	IN getting the AFS kernel modules to compile under linux I dicovered that
>>	the were useing the standard min(x,y) macro that whould evaluate which one
>>	is smaller. However sometime between 2.4.6 and 2.4.9 a new macro was added
>>	to linux/kernel.h
>>	
>>	this one:
>>	
>>	#define min(type,x,y) \
>>	        ({ type __x = (x), __y = (y); __x < __y ? __x: __y; })
>>	
>>	the old one is
>>	
>>	#define min(x,y) ( (x)<(y)?(x):(y) )
>>	
>>	has been around a lot longer and is in lots of header files.
>>	
>>	The problem here with AFS is that it needs the old definition but the old
>>	definition is being over written by the new one... you guys should know
>>	all this. But I am just saying that I really think the new macro
>>	min(type,x,y) should get a new name. like type_min or something.
>>	
>>	Thanks,
>>	
>>	Josie Imlay
>>	
>>	-
>>	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/
End of included message



-- 
twalberg@mindspring.com

[-- Attachment #2: Type: application/pgp-signature, Size: 175 bytes --]

  parent reply	other threads:[~2001-08-23 19:34 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 [this message]
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

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=20010823143440.G20693@mindspring.com \
    --to=twalberg@mindspring.com \
    --cc=jimlay@u.washington.edu \
    --cc=linux-kernel@vger.kernel.org \
    /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