public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Documentation: Explain a second alternative for multi-line macros.
@ 2006-12-31 19:32 Robert P. J. Day
  2006-12-31 19:45 ` Muli Ben-Yehuda
  2007-01-01 14:20 ` Christoph Hellwig
  0 siblings, 2 replies; 17+ messages in thread
From: Robert P. J. Day @ 2006-12-31 19:32 UTC (permalink / raw)
  To: Linux kernel mailing list; +Cc: Randy Dunlap, trivial


  Add an explanation for defining multi-line macros using the ({ })
notation to CodingStyle.

Signed-off-by: Robert P. J. Day <rpjday@mindspring.com>

---

diff --git a/Documentation/CodingStyle b/Documentation/CodingStyle
index 9069189..1d0ddb8 100644
--- a/Documentation/CodingStyle
+++ b/Documentation/CodingStyle
@@ -549,13 +549,24 @@ may be named in lower case.

 Generally, inline functions are preferable to macros resembling functions.

-Macros with multiple statements should be enclosed in a do - while block:
+There are two techniques for defining macros that contain multiple
+statements.

-#define macrofun(a, b, c) 			\
-	do {					\
+ (a) Enclose those statements in a do - while block:
+
+	#define macrofun(a, b, c) 		\
+		do {				\
+			if (a == 5)		\
+				do_this(b, c);	\
+		} while (0)
+
+ (b) Use the gcc extension that a compound statement enclosed in
+     parentheses represents an expression:
+
+	#define macrofun(a, b, c) ({		\
 		if (a == 5)			\
 			do_this(b, c);		\
-	} while (0)
+	})

 Things to avoid when using macros:


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH] Documentation: Explain a second alternative for multi-line macros.
  2006-12-31 19:32 [PATCH] Documentation: Explain a second alternative for multi-line macros Robert P. J. Day
@ 2006-12-31 19:45 ` Muli Ben-Yehuda
  2006-12-31 19:49   ` Robert P. J. Day
  2007-01-01 14:20 ` Christoph Hellwig
  1 sibling, 1 reply; 17+ messages in thread
From: Muli Ben-Yehuda @ 2006-12-31 19:45 UTC (permalink / raw)
  To: Robert P. J. Day; +Cc: Linux kernel mailing list, Randy Dunlap, trivial

On Sun, Dec 31, 2006 at 02:32:25PM -0500, Robert P. J. Day wrote:

>  Generally, inline functions are preferable to macros resembling
>  functions.

This should be stressed, IMHO. We have too many macros which have no
reason to live.

> -Macros with multiple statements should be enclosed in a do - while block:
> +There are two techniques for defining macros that contain multiple
> +statements.
> 
> -#define macrofun(a, b, c) 			\
> -	do {					\
> + (a) Enclose those statements in a do - while block:
> +
> +	#define macrofun(a, b, c) 		\
> +		do {				\
> +			if (a == 5)		\
> +				do_this(b, c);	\
> +		} while (0)
> +
> + (b) Use the gcc extension that a compound statement enclosed in
> +     parentheses represents an expression:
> +
> +	#define macrofun(a, b, c) ({		\
>  		if (a == 5)			\
>  			do_this(b, c);		\
> -	} while (0)
> +	})

When giving two alternatives, the reader will thank you if you explain
when each should be used. In this case, the second form should be used
when the macro needs to return a value (and you can't use an inline
function for whatever reason), whereas the first form should be used
at all other times.

Cheers,
Muli

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] Documentation: Explain a second alternative for multi-line macros.
  2006-12-31 19:45 ` Muli Ben-Yehuda
@ 2006-12-31 19:49   ` Robert P. J. Day
  2006-12-31 20:09     ` Muli Ben-Yehuda
  2007-01-01  2:40     ` Segher Boessenkool
  0 siblings, 2 replies; 17+ messages in thread
From: Robert P. J. Day @ 2006-12-31 19:49 UTC (permalink / raw)
  To: Muli Ben-Yehuda; +Cc: Linux kernel mailing list, Randy Dunlap, trivial

On Sun, 31 Dec 2006, Muli Ben-Yehuda wrote:

> On Sun, Dec 31, 2006 at 02:32:25PM -0500, Robert P. J. Day wrote:
>
> >  Generally, inline functions are preferable to macros resembling
> >  functions.
>
> This should be stressed, IMHO. We have too many macros which have no
> reason to live.
>
> > -Macros with multiple statements should be enclosed in a do - while block:
> > +There are two techniques for defining macros that contain multiple
> > +statements.
> >
> > -#define macrofun(a, b, c) 			\
> > -	do {					\
> > + (a) Enclose those statements in a do - while block:
> > +
> > +	#define macrofun(a, b, c) 		\
> > +		do {				\
> > +			if (a == 5)		\
> > +				do_this(b, c);	\
> > +		} while (0)
> > +
> > + (b) Use the gcc extension that a compound statement enclosed in
> > +     parentheses represents an expression:
> > +
> > +	#define macrofun(a, b, c) ({		\
> >  		if (a == 5)			\
> >  			do_this(b, c);		\
> > -	} while (0)
> > +	})
>
> When giving two alternatives, the reader will thank you if you
> explain when each should be used. In this case, the second form
> should be used when the macro needs to return a value (and you can't
> use an inline function for whatever reason), whereas the first form
> should be used at all other times.

that's a fair point, although it's certainly not the coding style
that's in play now.  for example,

  #define setcc(cc) ({ \
    partial_status &= ~(SW_C0|SW_C1|SW_C2|SW_C3); \
    partial_status |= (cc) & (SW_C0|SW_C1|SW_C2|SW_C3); })

there would appear to be *lots* of cases where the ({ }) notation is
used when nothing is being returned.  i'm not sure you can be that
adamant about that distinction at this point.

rday

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] Documentation: Explain a second alternative for multi-line macros.
  2006-12-31 20:09     ` Muli Ben-Yehuda
@ 2006-12-31 20:03       ` Randy Dunlap
  2006-12-31 20:13       ` Robert P. J. Day
  1 sibling, 0 replies; 17+ messages in thread
From: Randy Dunlap @ 2006-12-31 20:03 UTC (permalink / raw)
  To: Muli Ben-Yehuda; +Cc: Robert P. J. Day, Linux kernel mailing list, trivial

On Sun, 31 Dec 2006 22:09:03 +0200 Muli Ben-Yehuda wrote:

> On Sun, Dec 31, 2006 at 02:49:48PM -0500, Robert P. J. Day wrote:
> 
> > there would appear to be *lots* of cases where the ({ }) notation is
> > used when nothing is being returned.  i'm not sure you can be that
> > adamant about that distinction at this point.
> 
> IMHO, the main point of CodingStyle is to clarify how new code should
> be written and old code should've been written.

I agree.  We aren't trying to "fix" ancient history.

---
~Randy

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] Documentation: Explain a second alternative for multi-line macros.
  2006-12-31 19:49   ` Robert P. J. Day
@ 2006-12-31 20:09     ` Muli Ben-Yehuda
  2006-12-31 20:03       ` Randy Dunlap
  2006-12-31 20:13       ` Robert P. J. Day
  2007-01-01  2:40     ` Segher Boessenkool
  1 sibling, 2 replies; 17+ messages in thread
From: Muli Ben-Yehuda @ 2006-12-31 20:09 UTC (permalink / raw)
  To: Robert P. J. Day; +Cc: Linux kernel mailing list, Randy Dunlap, trivial

On Sun, Dec 31, 2006 at 02:49:48PM -0500, Robert P. J. Day wrote:

> there would appear to be *lots* of cases where the ({ }) notation is
> used when nothing is being returned.  i'm not sure you can be that
> adamant about that distinction at this point.

IMHO, the main point of CodingStyle is to clarify how new code should
be written and old code should've been written.

Cheers,
Muli

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] Documentation: Explain a second alternative for multi-line macros.
  2006-12-31 20:09     ` Muli Ben-Yehuda
  2006-12-31 20:03       ` Randy Dunlap
@ 2006-12-31 20:13       ` Robert P. J. Day
  1 sibling, 0 replies; 17+ messages in thread
From: Robert P. J. Day @ 2006-12-31 20:13 UTC (permalink / raw)
  To: Muli Ben-Yehuda; +Cc: Linux kernel mailing list, Randy Dunlap, trivial

On Sun, 31 Dec 2006, Muli Ben-Yehuda wrote:

> On Sun, Dec 31, 2006 at 02:49:48PM -0500, Robert P. J. Day wrote:
>
> > there would appear to be *lots* of cases where the ({ }) notation
> > is used when nothing is being returned.  i'm not sure you can be
> > that adamant about that distinction at this point.
>
> IMHO, the main point of CodingStyle is to clarify how new code
> should be written and old code should've been written.

ok, how about this as a patch:

diff --git a/Documentation/CodingStyle b/Documentation/CodingStyle
index 9069189..064a13e 100644
--- a/Documentation/CodingStyle
+++ b/Documentation/CodingStyle
@@ -549,13 +549,26 @@ may be named in lower case.

 Generally, inline functions are preferable to macros resembling functions.

-Macros with multiple statements should be enclosed in a do - while block:
-
-#define macrofun(a, b, c) 			\
-	do {					\
-		if (a == 5)			\
-			do_this(b, c);		\
-	} while (0)
+There are two techniques for defining macros that contain multiple
+statements, depending on whether you're returning a value or not:
+
+ (a) If there is no return value from the macro, you should enclose
+     the statements in a do - while block, as in:
+
+	#define macrofun(a, b, c) 		\
+		do {				\
+			if (a == 5)		\
+				do_this(b, c);	\
+		} while (0)
+
+ (b) If the macro is designed to return a value, you should use the
+     gcc extension that a compound statement enclosed in parentheses
+     represents an expression, as in:
+
+	#define maxint(a, b) ({			\
+		int _a = (a), _b = (b);		\
+		_a > _b ? _a : _b;		\
+	})

 Things to avoid when using macros:


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH] Documentation: Explain a second alternative for multi-line macros.
  2006-12-31 19:49   ` Robert P. J. Day
  2006-12-31 20:09     ` Muli Ben-Yehuda
@ 2007-01-01  2:40     ` Segher Boessenkool
  2007-01-01  3:23       ` Randy Dunlap
  2007-01-01  8:26       ` Robert P. J. Day
  1 sibling, 2 replies; 17+ messages in thread
From: Segher Boessenkool @ 2007-01-01  2:40 UTC (permalink / raw)
  To: Robert P. J. Day
  Cc: Muli Ben-Yehuda, Randy Dunlap, Linux kernel mailing list, trivial

>> In this case, the second form
>> should be used when the macro needs to return a value (and you can't
>> use an inline function for whatever reason), whereas the first form
>> should be used at all other times.
>
> that's a fair point, although it's certainly not the coding style
> that's in play now.  for example,
>
>   #define setcc(cc) ({ \
>     partial_status &= ~(SW_C0|SW_C1|SW_C2|SW_C3); \
>     partial_status |= (cc) & (SW_C0|SW_C1|SW_C2|SW_C3); })

This _does_ return a value though, bad example.


Segher


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] Documentation: Explain a second alternative for multi-line macros.
  2007-01-01  2:40     ` Segher Boessenkool
@ 2007-01-01  3:23       ` Randy Dunlap
  2007-01-01  4:31         ` Segher Boessenkool
  2007-01-01 15:37         ` Jan Engelhardt
  2007-01-01  8:26       ` Robert P. J. Day
  1 sibling, 2 replies; 17+ messages in thread
From: Randy Dunlap @ 2007-01-01  3:23 UTC (permalink / raw)
  To: Segher Boessenkool
  Cc: Robert P. J. Day, Muli Ben-Yehuda, Linux kernel mailing list,
	trivial

Segher Boessenkool wrote:
>>> In this case, the second form
>>> should be used when the macro needs to return a value (and you can't
>>> use an inline function for whatever reason), whereas the first form
>>> should be used at all other times.
>>
>> that's a fair point, although it's certainly not the coding style
>> that's in play now.  for example,
>>
>>   #define setcc(cc) ({ \
>>     partial_status &= ~(SW_C0|SW_C1|SW_C2|SW_C3); \
>>     partial_status |= (cc) & (SW_C0|SW_C1|SW_C2|SW_C3); })
> 
> This _does_ return a value though, bad example.

Where does it return a value?  I don't see any uses of it
in arch/i386/math-emu/* that use it as returning a value.

And with a small change to put it inside a do-while block
instead of ({ ... }), it at least builds cleanly.
I expected some complaints.

-- 
~Randy

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] Documentation: Explain a second alternative for multi-line macros.
  2007-01-01  4:31         ` Segher Boessenkool
@ 2007-01-01  4:30           ` Randy Dunlap
  0 siblings, 0 replies; 17+ messages in thread
From: Randy Dunlap @ 2007-01-01  4:30 UTC (permalink / raw)
  To: Segher Boessenkool
  Cc: Muli Ben-Yehuda, Linux kernel mailing list, Robert P. J. Day,
	trivial

Segher Boessenkool wrote:
>>>>   #define setcc(cc) ({ \
>>>>     partial_status &= ~(SW_C0|SW_C1|SW_C2|SW_C3); \
>>>>     partial_status |= (cc) & (SW_C0|SW_C1|SW_C2|SW_C3); })
>>> This _does_ return a value though, bad example.
>>
>> Where does it return a value?
> 
> partial_status |=

as I expected (or suspected).
I also suspect that it wasn't intended, but this is old code
and I wasn't around Linux when it was written, so I don't know
about it for sure.

>> I don't see any uses of it
> 
> Ah, that's a separate thing -- it returns a value, it's just
> never used.

Ack.

>> And with a small change to put it inside a do-while block
>> instead of ({ ... }), it at least builds cleanly.
> 
> Well please replace it then, statement expressions should be
> avoided where possible (to start with, they don't have well-
> defined semantics).

We should probably avoid gcc extensions when possible.

I'll send a separate email for the patch.

-- 
~Randy

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] Documentation: Explain a second alternative for multi-line macros.
  2007-01-01  3:23       ` Randy Dunlap
@ 2007-01-01  4:31         ` Segher Boessenkool
  2007-01-01  4:30           ` Randy Dunlap
  2007-01-01 15:37         ` Jan Engelhardt
  1 sibling, 1 reply; 17+ messages in thread
From: Segher Boessenkool @ 2007-01-01  4:31 UTC (permalink / raw)
  To: Randy Dunlap
  Cc: Muli Ben-Yehuda, Linux kernel mailing list, Robert P. J. Day,
	trivial

>>>   #define setcc(cc) ({ \
>>>     partial_status &= ~(SW_C0|SW_C1|SW_C2|SW_C3); \
>>>     partial_status |= (cc) & (SW_C0|SW_C1|SW_C2|SW_C3); })
>> This _does_ return a value though, bad example.
>
> Where does it return a value?

partial_status |=

> I don't see any uses of it

Ah, that's a separate thing -- it returns a value, it's just
never used.

> And with a small change to put it inside a do-while block
> instead of ({ ... }), it at least builds cleanly.

Well please replace it then, statement expressions should be
avoided where possible (to start with, they don't have well-
defined semantics).


Segher


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] Documentation: Explain a second alternative for multi-line macros.
  2007-01-01  2:40     ` Segher Boessenkool
  2007-01-01  3:23       ` Randy Dunlap
@ 2007-01-01  8:26       ` Robert P. J. Day
  1 sibling, 0 replies; 17+ messages in thread
From: Robert P. J. Day @ 2007-01-01  8:26 UTC (permalink / raw)
  To: Segher Boessenkool
  Cc: Muli Ben-Yehuda, Randy Dunlap, Linux kernel mailing list, trivial

On Mon, 1 Jan 2007, Segher Boessenkool wrote:

> > > In this case, the second form
> > > should be used when the macro needs to return a value (and you can't
> > > use an inline function for whatever reason), whereas the first form
> > > should be used at all other times.
> >
> > that's a fair point, although it's certainly not the coding style
> > that's in play now.  for example,
> >
> >   #define setcc(cc) ({ \
> >     partial_status &= ~(SW_C0|SW_C1|SW_C2|SW_C3); \
> >     partial_status |= (cc) & (SW_C0|SW_C1|SW_C2|SW_C3); })
>
> This _does_ return a value though, bad example.

sigh ... you're right.  here's a thought.  my original patch
submission simply added an explanation for allowing the ({ }) notation
for defining a multi-line macro, without getting into recommending an
actual coding style.  at a minimum, something like that should be
added to the style document.

if someone wants to extend that explanation recommending *when* each
of those two styles should be used, feel free.  but a simple
decription of alternatives should *at least* be added, no?

rday

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] Documentation: Explain a second alternative for multi-line macros.
  2006-12-31 19:32 [PATCH] Documentation: Explain a second alternative for multi-line macros Robert P. J. Day
  2006-12-31 19:45 ` Muli Ben-Yehuda
@ 2007-01-01 14:20 ` Christoph Hellwig
  2007-01-01 14:25   ` Robert P. J. Day
  1 sibling, 1 reply; 17+ messages in thread
From: Christoph Hellwig @ 2007-01-01 14:20 UTC (permalink / raw)
  To: Robert P. J. Day; +Cc: Linux kernel mailing list, Randy Dunlap, trivial

On Sun, Dec 31, 2006 at 02:32:25PM -0500, Robert P. J. Day wrote:
> + (a) Enclose those statements in a do - while block:
> +
> +	#define macrofun(a, b, c) 		\
> +		do {				\
> +			if (a == 5)		\
> +				do_this(b, c);	\
> +		} while (0)

nitpick, please don't add an indentaion level for the do {.  Do this
should look like:

	#define macrofun(a, b, c) 	\
	do {				\
		if (a == 5)		\
			do_this(b, c);	\
	} while (0)


> + (b) Use the gcc extension that a compound statement enclosed in
> +     parentheses represents an expression:
> +
> +	#define macrofun(a, b, c) ({		\
>  		if (a == 5)			\
>  			do_this(b, c);		\
> -	} while (0)
> +	})

I'd rather document to not use this - it makes the code far less
redable.  And it's a non-standard extension, something we only
use if it provides us a benefit which it doesn't here.


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] Documentation: Explain a second alternative for multi-line macros.
  2007-01-01 14:20 ` Christoph Hellwig
@ 2007-01-01 14:25   ` Robert P. J. Day
  2007-01-01 16:14     ` Randy Dunlap
  0 siblings, 1 reply; 17+ messages in thread
From: Robert P. J. Day @ 2007-01-01 14:25 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Linux kernel mailing list, Randy Dunlap, trivial

On Mon, 1 Jan 2007, Christoph Hellwig wrote:

> On Sun, Dec 31, 2006 at 02:32:25PM -0500, Robert P. J. Day wrote:
> > + (a) Enclose those statements in a do - while block:
> > +
> > +	#define macrofun(a, b, c) 		\
> > +		do {				\
> > +			if (a == 5)		\
> > +				do_this(b, c);	\
> > +		} while (0)
>
> nitpick, please don't add an indentaion level for the do {.  Do this
> should look like:
>
> 	#define macrofun(a, b, c) 	\
> 	do {				\
> 		if (a == 5)		\
> 			do_this(b, c);	\
> 	} while (0)

the former is the way it's presented in CodingStyle currently, it
wasn't my personal opinion on the subject.  i was just reproducing
what was already there.

> > + (b) Use the gcc extension that a compound statement enclosed in
> > +     parentheses represents an expression:
> > +
> > +	#define macrofun(a, b, c) ({		\
> >  		if (a == 5)			\
> >  			do_this(b, c);		\
> > -	} while (0)
> > +	})
>
> I'd rather document to not use this - it makes the code far less
> redable.  And it's a non-standard extension, something we only
> use if it provides us a benefit which it doesn't here.

it might be a bit late to put a cork in *that* bottle:

  $ grep -r "#define.*({" *

rday

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] Documentation: Explain a second alternative for multi-line macros.
  2007-01-01  3:23       ` Randy Dunlap
  2007-01-01  4:31         ` Segher Boessenkool
@ 2007-01-01 15:37         ` Jan Engelhardt
  2007-01-01 17:51           ` Segher Boessenkool
  1 sibling, 1 reply; 17+ messages in thread
From: Jan Engelhardt @ 2007-01-01 15:37 UTC (permalink / raw)
  To: Randy Dunlap
  Cc: Segher Boessenkool, Robert P. J. Day, Muli Ben-Yehuda,
	Linux kernel mailing list, trivial


On Dec 31 2006 19:23, Randy Dunlap wrote:
>> > 
>> > #define setcc(cc) ({ \
>> > partial_status &= ~(SW_C0|SW_C1|SW_C2|SW_C3); \
>> > partial_status |= (cc) & (SW_C0|SW_C1|SW_C2|SW_C3); })
>> 
>> This _does_ return a value though, bad example.
>
> Where does it return a value?  I don't see any uses of it
> in arch/i386/math-emu/* that use it as returning a value.
>
> And with a small change to put it inside a do-while block
> instead of ({ ... }), it at least builds cleanly.
> I expected some complaints.

If people want to return something from a ({ }) construct, they should do it
explicitly, e.g.

#define setcc(cc) ({ \
	partial_status &= ~(SW_C0|SW_C1|SW_C2|SW_C3); \
	partial_status |= (cc) & (SW_C0|SW_C1|SW_C2|SW_C3); \
	partial_status; \
})


	-`J'
-- 

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] Documentation: Explain a second alternative for multi-line macros.
  2007-01-01 14:25   ` Robert P. J. Day
@ 2007-01-01 16:14     ` Randy Dunlap
  0 siblings, 0 replies; 17+ messages in thread
From: Randy Dunlap @ 2007-01-01 16:14 UTC (permalink / raw)
  To: Robert P. J. Day; +Cc: Christoph Hellwig, Linux kernel mailing list, trivial

Robert P. J. Day wrote:
> On Mon, 1 Jan 2007, Christoph Hellwig wrote:
> 
>> On Sun, Dec 31, 2006 at 02:32:25PM -0500, Robert P. J. Day wrote:
>>> + (a) Enclose those statements in a do - while block:
>>> +
>>> +	#define macrofun(a, b, c) 		\
>>> +		do {				\
>>> +			if (a == 5)		\
>>> +				do_this(b, c);	\
>>> +		} while (0)
>> nitpick, please don't add an indentaion level for the do {.  Do this
>> should look like:
>>
>> 	#define macrofun(a, b, c) 	\
>> 	do {				\
>> 		if (a == 5)		\
>> 			do_this(b, c);	\
>> 	} while (0)
> 
> the former is the way it's presented in CodingStyle currently, it
> wasn't my personal opinion on the subject.  i was just reproducing
> what was already there.
> 
>>> + (b) Use the gcc extension that a compound statement enclosed in
>>> +     parentheses represents an expression:
>>> +
>>> +	#define macrofun(a, b, c) ({		\
>>>  		if (a == 5)			\
>>>  			do_this(b, c);		\
>>> -	} while (0)
>>> +	})
>> I'd rather document to not use this - it makes the code far less
>> redable.  And it's a non-standard extension, something we only
>> use if it provides us a benefit which it doesn't here.
> 
> it might be a bit late to put a cork in *that* bottle:
> 
>   $ grep -r "#define.*({" *

We aren't trying to prevent its past use.  We just aren't encouraging
the use of gcc extensions if there are reasonable & better ways to
do something.

-- 
~Randy

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] Documentation: Explain a second alternative for multi-line macros.
  2007-01-01 15:37         ` Jan Engelhardt
@ 2007-01-01 17:51           ` Segher Boessenkool
  2007-01-01 19:11             ` Jan Engelhardt
  0 siblings, 1 reply; 17+ messages in thread
From: Segher Boessenkool @ 2007-01-01 17:51 UTC (permalink / raw)
  To: Jan Engelhardt
  Cc: Robert P. J. Day, trivial, Randy Dunlap, Muli Ben-Yehuda,
	Linux kernel mailing list

> If people want to return something from a ({ }) construct, they should 
> do it
> explicitly, e.g.
>
> #define setcc(cc) ({ \
> 	partial_status &= ~(SW_C0|SW_C1|SW_C2|SW_C3); \
> 	partial_status |= (cc) & (SW_C0|SW_C1|SW_C2|SW_C3); \
> 	partial_status; \
> })

No, they generally should use an inline function instead.


Segher


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] Documentation: Explain a second alternative for multi-line macros.
  2007-01-01 17:51           ` Segher Boessenkool
@ 2007-01-01 19:11             ` Jan Engelhardt
  0 siblings, 0 replies; 17+ messages in thread
From: Jan Engelhardt @ 2007-01-01 19:11 UTC (permalink / raw)
  To: Segher Boessenkool
  Cc: Robert P. J. Day, trivial, Randy Dunlap, Muli Ben-Yehuda,
	Linux kernel mailing list


On Jan 1 2007 18:51, Segher Boessenkool wrote:
>> If people want to return something from a ({ }) construct, they should do
>> it
>> explicitly, e.g.
>> 
>> #define setcc(cc) ({ \
>> partial_status &= ~(SW_C0|SW_C1|SW_C2|SW_C3); \
>> partial_status |= (cc) & (SW_C0|SW_C1|SW_C2|SW_C3); \
>> partial_status; \
>> })
>
> No, they generally should use an inline function instead.

Perhaps. But that won't work with defines where typeof is involved.


	-`J'
-- 

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2007-01-01 19:15 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-12-31 19:32 [PATCH] Documentation: Explain a second alternative for multi-line macros Robert P. J. Day
2006-12-31 19:45 ` Muli Ben-Yehuda
2006-12-31 19:49   ` Robert P. J. Day
2006-12-31 20:09     ` Muli Ben-Yehuda
2006-12-31 20:03       ` Randy Dunlap
2006-12-31 20:13       ` Robert P. J. Day
2007-01-01  2:40     ` Segher Boessenkool
2007-01-01  3:23       ` Randy Dunlap
2007-01-01  4:31         ` Segher Boessenkool
2007-01-01  4:30           ` Randy Dunlap
2007-01-01 15:37         ` Jan Engelhardt
2007-01-01 17:51           ` Segher Boessenkool
2007-01-01 19:11             ` Jan Engelhardt
2007-01-01  8:26       ` Robert P. J. Day
2007-01-01 14:20 ` Christoph Hellwig
2007-01-01 14:25   ` Robert P. J. Day
2007-01-01 16:14     ` Randy Dunlap

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox