Hi all, Some time ago I posted about a question about some cleanup of what I thought looked like some strange code in the kernel - specifically about the sock_rcvlowat() function in linux/include/net/sock.h static inline int sock_rcvlowat(struct sock *sk, int waitall, int len) { return (waitall ? len : min(sk->rcvlowat, len)) ? : 1; } The empty second expression puzzled me. Mark Hahn (amongst many other people) pointed out to me that it was a valid gcc extention (thank you), but I still found it hard to read and exchanged several emails with Mark about how to improve the function. Mark came up with a much more readable version that achieves the exact same result and generates just as good (if not better) code than the original one-line function - the function below: static inline int sock_rcvlowat(struct sock *sk, int waitall, int len) { int r = len; if (!waitall) r = min(sk->rcvlowat, len); return max(1,r); } I have included a patch below (against 2.4.5pre1) that makes the change to the more readable version and would like people on the list to consider it as a replacement. Credit for the code should go 100% to Mark as he wrote it, I'm just submitting it to the list since I found it so nice :-) --- linux-2.4.5pre1/include/net/sock.h Tue May 8 00:12:14 2001 +++ linux/include/net/sock.h Tue May 8 00:46:43 2001 @@ -1265,7 +1265,10 @@ static inline int sock_rcvlowat(struct sock *sk, int waitall, int len) { - return (waitall ? len : min(sk->rcvlowat, len)) ? : 1; + int r = len; + if (!waitall) + r = min(sk->rcvlowat, len); + return max(1,r); } /* Alas, with timeout socket operations are not restartable. Best regards, Jesper Juhl - [EMAIL PROTECTED] - struggeling to understand this magnificent kernel beast ;) - - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/