diff mbox

[03/15] batman-adv: add biggest_unsigned_int(x) macro

Message ID 1335360431-30027-4-git-send-email-ordex@autistici.org
State Changes Requested, archived
Delegated to: David Miller
Headers show

Commit Message

Antonio Quartulli April 25, 2012, 1:26 p.m. UTC
in case of dynamic type variable, it could be needed to compute at compile time
its maximal value. This macro helps in doing that for unsigned integer types

Signed-off-by: Antonio Quartulli <ordex@autistici.org>
---
 net/batman-adv/main.h |    3 +++
 1 file changed, 3 insertions(+)

Comments

David Laight April 25, 2012, 2:14 p.m. UTC | #1
> +/* Returns the biggest unsigned integer with the sizeof x */
> +#define biggest_unsigned_int(x) (~(x)0)

Nope - biggest_unsigned_int(unsigned char) is probably 0xffffffff

	David


--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Laight April 25, 2012, 2:57 p.m. UTC | #2
> > +/* Returns the biggest unsigned integer with the sizeof x */
> > +#define biggest_unsigned_int(x) (~(x)0)
> 
> Nope - biggest_unsigned_int(unsigned char) is probably 0xffffffff

To correct myself, it is actually ((int)(-1)) (ie a signed value).

	David


--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Miller April 25, 2012, 6:09 p.m. UTC | #3
From: "David Laight" <David.Laight@ACULAB.COM>
Date: Wed, 25 Apr 2012 15:57:39 +0100

>  
>> > +/* Returns the biggest unsigned integer with the sizeof x */
>> > +#define biggest_unsigned_int(x) (~(x)0)
>> 
>> Nope - biggest_unsigned_int(unsigned char) is probably 0xffffffff
> 
> To correct myself, it is actually ((int)(-1)) (ie a signed value).

In any event this is just a terrible macro, and too stupid to live.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Antonio Quartulli April 27, 2012, 12:51 p.m. UTC | #4
Il 25.04.2012 20:09 David Miller ha scritto:
> From: "David Laight" <David.Laight@ACULAB.COM>
> Date: Wed, 25 Apr 2012 15:57:39 +0100
>
>>
>>> > +/* Returns the biggest unsigned integer with the sizeof x */
>>> > +#define biggest_unsigned_int(x) (~(x)0)
>>>
>>> Nope - biggest_unsigned_int(unsigned char) is probably 0xffffffff
>>
>> To correct myself, it is actually ((int)(-1)) (ie a signed value).
>
> In any event this is just a terrible macro, and too stupid to live.

Hello David,

ok. So the suggestion is to directly use the ~ operator in the code 
without creating a macro.
If the rest of the patchset is ok, I will eliminate this macro and 
resend the pull request again.

Cheers,
diff mbox

Patch

diff --git a/net/batman-adv/main.h b/net/batman-adv/main.h
index a2b18d0..d9ef4ca 100644
--- a/net/batman-adv/main.h
+++ b/net/batman-adv/main.h
@@ -221,6 +221,9 @@  static inline bool has_timed_out(unsigned long timestamp, unsigned int timeout)
 /* Returns the smallest signed integer in two's complement with the sizeof x */
 #define smallest_signed_int(x) (1u << (7u + 8u * (sizeof(x) - 1u)))
 
+/* Returns the biggest unsigned integer with the sizeof x */
+#define biggest_unsigned_int(x) (~(x)0)
+
 /* Checks if a sequence number x is a predecessor/successor of y.
  * they handle overflows/underflows and can correctly check for a
  * predecessor/successor unless the variable sequence number has grown by