LWN.net Logo

Quotes of the week

+/*
+ * "Define 'is'", Bill Clinton
+ * "Define 'if'", Steven Rostedt
+ */
+#define if(cond) if (__builtin_constant_p((cond)) ? !!(cond) :		\
+	({								\
+		int ______r;						\
+		static struct ftrace_branch_data			\
+			__attribute__((__aligned__(4)))			\
+			__attribute__((section("_ftrace_branch")))	\
+			______f = {					\
+				.func = __func__,			\
+				.file = __FILE__,			\
+				.line = __LINE__,			\
+			};						\
+		______r = !!(cond);					\
+		if (______r)						\
+			______f.hit++;					\
+		else							\
+			______f.miss++;					\
+		______r;						\
+	}))
-- Steven Rostedt debuts the new "if"

Working on lkml often sounds like everyone is screaming NO, channeling nothing but stop energy. Sometimes people are, but more often what they really mean is you just have to take your time and do things right. Admittedly it is a lot of iteration, but Linux is a noble pursuit.
-- Robert Love

But let's look at the problem which we're actually trying to solve. Developer A wishes to write some kernel monitoring/controlling code, so he is forced to stick it on his website, keep reminding people to download updates, act as an independent target of other people's patches, etc, etc. It's all a pain and horror, so developer A gives up and implements his userspace code in the kernel instead. It is, as a result, technically inferior and English-only, but at least it got there.
-- Andrew Morton
(Log in to post comments)

Quotes of the week

Posted Nov 26, 2008 23:00 UTC (Wed) by nix (subscriber, #2304) [Link]

Steven's post underscores the problem with trying to do this sort of thing
elegantly in C.

Quotes of the week

Posted Nov 26, 2008 23:15 UTC (Wed) by gevaerts (subscriber, #21521) [Link]

What's so inelegant about it?

Quotes of the week

Posted Nov 27, 2008 0:36 UTC (Thu) by nix (subscriber, #2304) [Link]

Please upgrade your bad pun detector. :)

Quotes of the week

Posted Nov 27, 2008 12:31 UTC (Thu) by gevaerts (subscriber, #21521) [Link]

Thanks for the hint. After upgrading it works properly :)

Quotes of the week

Posted Nov 26, 2008 23:32 UTC (Wed) by bronson (subscriber, #4806) [Link]

I'm not sure about that... There are few languages that would allow so perverse an idea to be more elegant (Forth, Lisp and Smalltalk being notable exceptions of course).

And I use "perverse" purely in the good sense of the word. :)

Quotes of the week

Posted Dec 4, 2008 8:01 UTC (Thu) by eduperez (guest, #11232) [Link]

Perhaps PL/I should be added to the list: in this language, macros are PL/I snippets, executed during compile time, that produce a block of code, which is incorporated into the main code and compiled.

Quotes of the week

Posted Nov 27, 2008 0:26 UTC (Thu) by felixfix (subscriber, #242) [Link]

I third this. My first reaction was raised eyebrows and a whistle of admiration. C is a wondrous language that too many people disparage from ignorance.

Quotes of the week

Posted Nov 27, 2008 2:42 UTC (Thu) by ncm (subscriber, #165) [Link]

+2 for use of obscure definition of "wondrous". Agree that more people should disparage C from familiarity.

Quotes of the week

Posted Nov 27, 2008 6:42 UTC (Thu) by flewellyn (subscriber, #5047) [Link]

"Underscores" indeed. That was AWFUL. Next time, warn us so we can brace ourselves.

Quotes of the week

Posted Nov 30, 2008 22:23 UTC (Sun) by k8to (subscriber, #15413) [Link]

I'm not sure I see the point of your paranthetical aside.

Quotes of the week

Posted Nov 30, 2008 23:43 UTC (Sun) by nix (subscriber, #2304) [Link]

OK, you two have neatly bracketed my pun. I think it's line to put a line
through this now.

Quotes of the week

Posted Nov 27, 2008 23:05 UTC (Thu) by smitty_one_each (subscriber, #28989) [Link]

I think that the Bill Clinton reference, referring to the question of whether he'd had sex with Monicia Lewinsky "It depends upon what your definition of 'is' is" is actually funner.
(I will now go flog myself for the triple usage of "to be" in the third person singular.)

underscores

Posted Dec 2, 2008 22:28 UTC (Tue) by rfunk (subscriber, #4054) [Link]

Dunno, looks a lot like Python to me...

Oh yeah, that's one of the things I dislike about Python.

if

Posted Nov 27, 2008 3:53 UTC (Thu) by dskoll (subscriber, #1630) [Link]

Wow... that "if" macro really works? I had no idea you could use a block inside an expression. Please tell me that's a gcc extension...

if

Posted Nov 27, 2008 5:21 UTC (Thu) by jamesh (guest, #1159) [Link]

It is a GCC extension.

if

Posted Nov 27, 2008 10:27 UTC (Thu) by nix (subscriber, #2304) [Link]

For added fun, figure out the lifetime rules for C++ types with destructors across the terminating brace of a statement expression. There are almost certainly still ways to crash the compiler in here :( statement expressions work well with C and are definitely readability enhancers, but get really tangled and unpleasant to think about when C++ gets involved.

(Thankfully the most substantial use of this extension in C++ is its use in the glibc headers, which don't use it with non-POD types.)

if macro and C++

Posted Nov 28, 2008 22:52 UTC (Fri) by pr1268 (subscriber, #24648) [Link]

For added fun, figure out the lifetime rules for C++ types with destructors across the terminating brace of a statement expression.

Hehe, I just learned recently about how often C++ programmers will use curl-braces in their code simply to exploit the whole constructor/destructor scoping rules. RAII seemed wacky to me at first, but in retrospect it appears necessary with C++'s home-brewed type capabilities (Classes, that is).

if macro and C++

Posted Nov 29, 2008 1:24 UTC (Sat) by nix (subscriber, #2304) [Link]

I think it's actually quite elegant: an intuitively pleasant
generalization of the concept of variable scope. (There aren't many things
about C++ that are intuitively pleasant, but RAII is one of them.)

Copyright © 2008, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds