Re: svn commit: r312236 - head/sys/net80211

2017-01-17 Thread Andriy Gapon
On 15/01/2017 22:43, Adrian Chadd wrote:
> On 15 January 2017 at 11:56, Ian Lepore  wrote:
> 
>>
>> What is the point of the !! in these macros?  The expressions already
>> have boolean type (even in C++ where it matters) due to the ==.
>>  Removing the !! would also make one level of parens redundant.
> 
> It's just a habit i picked up from linux-land. That way it really is
> only 1 or 0, so things like debugging output and such make easier
> sense.

Well, that habit is useful when applied to results of bit-wise operations.
It does nothing but obfuscating the code when applied to results of logical
operations.  Which is the case here.
And even with the bit-wise operation we have a FreeBSD idiom of comparing the
result with zero using != 0.  More verbose, but also more stylish.

> It's also fixed a handful of bugs in the past (but I can't think of
> exact cases right now) - primarily where other code expected 1 or 0
> (for things like shifts into protocol fields) and the macro returns 0
> or ${LARGEVAL}.


-- 
Andriy Gapon
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r312236 - head/sys/net80211

2017-01-15 Thread Adrian Chadd
On 15 January 2017 at 11:56, Ian Lepore  wrote:

>
> What is the point of the !! in these macros?  The expressions already
> have boolean type (even in C++ where it matters) due to the ==.
>  Removing the !! would also make one level of parens redundant.

It's just a habit i picked up from linux-land. That way it really is
only 1 or 0, so things like debugging output and such make easier
sense.

It's also fixed a handful of bugs in the past (but I can't think of
exact cases right now) - primarily where other code expected 1 or 0
(for things like shifts into protocol fields) and the macro returns 0
or ${LARGEVAL}.



-adrian
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r312236 - head/sys/net80211

2017-01-15 Thread Ian Lepore
On Sun, 2017-01-15 at 19:49 +, Adrian Chadd wrote:
> Author: adrian
> Date: Sun Jan 15 19:49:47 2017
> New Revision: 312236
> URL: https://svnweb.freebsd.org/changeset/base/312236
> 
> Log:
>   [net80211] add some more "is this XXX" macros for CTRL and DATA.
>   
>   There's already a macro for MGT.
> 
> Modified:
>   head/sys/net80211/ieee80211.h
> 
> Modified: head/sys/net80211/ieee80211.h
> =
> =
> --- head/sys/net80211/ieee80211.h Sun Jan 15 18:00:45 2017
> (r312235)
> +++ head/sys/net80211/ieee80211.h Sun Jan 15 19:49:47 2017
> (r312236)
> @@ -165,6 +165,12 @@ struct ieee80211_qosframe_addr4 {
>  #define  IEEE80211_IS_MGMT(wh)   
> \
>   (!! (((wh)->i_fc[0] & IEEE80211_FC0_TYPE_MASK)  
> \
>   == IEEE80211_FC0_TYPE_MGT))
> +#define  IEEE80211_IS_CTL(wh)
> \
> + (!! (((wh)->i_fc[0] & IEEE80211_FC0_TYPE_MASK)  
> \
> + == IEEE80211_FC0_TYPE_CTL))
> +#define  IEEE80211_IS_DATA(wh)   
> \
> + (!! (((wh)->i_fc[0] & IEEE80211_FC0_TYPE_MASK)  
> \
> + == IEEE80211_FC0_TYPE_DATA))
>  
>  #define  IEEE80211_FC0_QOSDATA \
>   (IEEE80211_FC0_TYPE_DATA|IEEE80211_FC0_SUBTYPE_QOS|IEEE80211
> _FC0_VERSION_0)
> 

What is the point of the !! in these macros?  The expressions already
have boolean type (even in C++ where it matters) due to the ==.
 Removing the !! would also make one level of parens redundant.

-- Ian
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r312236 - head/sys/net80211

2017-01-15 Thread Adrian Chadd
Author: adrian
Date: Sun Jan 15 19:49:47 2017
New Revision: 312236
URL: https://svnweb.freebsd.org/changeset/base/312236

Log:
  [net80211] add some more "is this XXX" macros for CTRL and DATA.
  
  There's already a macro for MGT.

Modified:
  head/sys/net80211/ieee80211.h

Modified: head/sys/net80211/ieee80211.h
==
--- head/sys/net80211/ieee80211.h   Sun Jan 15 18:00:45 2017
(r312235)
+++ head/sys/net80211/ieee80211.h   Sun Jan 15 19:49:47 2017
(r312236)
@@ -165,6 +165,12 @@ struct ieee80211_qosframe_addr4 {
 #defineIEEE80211_IS_MGMT(wh)   \
(!! (((wh)->i_fc[0] & IEEE80211_FC0_TYPE_MASK)  \
== IEEE80211_FC0_TYPE_MGT))
+#defineIEEE80211_IS_CTL(wh)\
+   (!! (((wh)->i_fc[0] & IEEE80211_FC0_TYPE_MASK)  \
+   == IEEE80211_FC0_TYPE_CTL))
+#defineIEEE80211_IS_DATA(wh)   \
+   (!! (((wh)->i_fc[0] & IEEE80211_FC0_TYPE_MASK)  \
+   == IEEE80211_FC0_TYPE_DATA))
 
 #defineIEEE80211_FC0_QOSDATA \

(IEEE80211_FC0_TYPE_DATA|IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_VERSION_0)
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"