public inbox for b.a.t.m.a.n@lists.open-mesh.org
 help / color / mirror / Atom feed
* [B.A.T.M.A.N.] [PATCH] batman-adv: add biggest_unsigned_int(x) macro
@ 2011-11-23 10:35 Antonio Quartulli
  2011-11-25  1:08 ` Marek Lindner
  2012-02-11 11:03 ` Marek Lindner
  0 siblings, 2 replies; 5+ messages in thread
From: Antonio Quartulli @ 2011-11-23 10:35 UTC (permalink / raw)
  To: b.a.t.m.a.n

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>
---
 main.h |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/main.h b/main.h
index 464439f..3c58235 100644
--- a/main.h
+++ b/main.h
@@ -210,6 +210,9 @@ static inline int compare_eth(const void *data1, const void *data2)
 /* 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
-- 
1.7.3.4


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

* Re: [B.A.T.M.A.N.] [PATCH] batman-adv: add biggest_unsigned_int(x) macro
  2011-11-23 10:35 [B.A.T.M.A.N.] [PATCH] batman-adv: add biggest_unsigned_int(x) macro Antonio Quartulli
@ 2011-11-25  1:08 ` Marek Lindner
  2011-11-25  8:50   ` Sven Eckelmann
  2012-02-11 11:03 ` Marek Lindner
  1 sibling, 1 reply; 5+ messages in thread
From: Marek Lindner @ 2011-11-25  1:08 UTC (permalink / raw)
  To: The list for a Better Approach To Mobile Ad-hoc Networking

On Wednesday, November 23, 2011 18:35:44 Antonio Quartulli wrote:
> 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>
> ---
>  main.h |    3 +++
>  1 files changed, 3 insertions(+), 0 deletions(-)
> 
> diff --git a/main.h b/main.h
> index 464439f..3c58235 100644
> --- a/main.h
> +++ b/main.h
> @@ -210,6 +210,9 @@ static inline int compare_eth(const void *data1, const
> void *data2) /* 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)
> +

The final conclusion of the IRC discussion might have escaped me but wasn't 
there supposed to be a cast somewhere ?

Regards,
Marek

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

* Re: [B.A.T.M.A.N.] [PATCH] batman-adv: add biggest_unsigned_int(x) macro
  2011-11-25  1:08 ` Marek Lindner
@ 2011-11-25  8:50   ` Sven Eckelmann
  2011-11-25 10:53     ` Antonio Quartulli
  0 siblings, 1 reply; 5+ messages in thread
From: Sven Eckelmann @ 2011-11-25  8:50 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: Marek Lindner

[-- Attachment #1: Type: text/plain, Size: 700 bytes --]

On Friday 25 November 2011 09:08:47 Marek Lindner wrote:
[...]
> > +/* Returns the biggest unsigned integer with the sizeof x */
> > +#define biggest_unsigned_int(x) (~(x)0)
> > +
> 
> The final conclusion of the IRC discussion might have escaped me but wasn't
> there supposed to be a cast somewhere ?

There is a cast. The part "(x)" of "(~(x)0)" is the cast. And I don't think 
that there was a final conclusion. I am not really convinced that this should 
be part of batman-adv. Just look at include/linux/kernel.h for similar 
functionality (but with predefined types). Maybe this would be the correct 
position for such a macro? (I don't know it... just thinking out loud).

Kind regards,
	Sven

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* Re: [B.A.T.M.A.N.] [PATCH] batman-adv: add biggest_unsigned_int(x) macro
  2011-11-25  8:50   ` Sven Eckelmann
@ 2011-11-25 10:53     ` Antonio Quartulli
  0 siblings, 0 replies; 5+ messages in thread
From: Antonio Quartulli @ 2011-11-25 10:53 UTC (permalink / raw)
  To: The list for a Better Approach To Mobile Ad-hoc Networking; +Cc: Marek Lindner

On Fri, Nov 25, 2011 at 09:50:41AM +0100, Sven Eckelmann wrote:
> On Friday 25 November 2011 09:08:47 Marek Lindner wrote:
> [...]
> > > +/* Returns the biggest unsigned integer with the sizeof x */
> > > +#define biggest_unsigned_int(x) (~(x)0)
> > > +
> > 
> > The final conclusion of the IRC discussion might have escaped me but wasn't
> > there supposed to be a cast somewhere ?
> 
> There is a cast. The part "(x)" of "(~(x)0)" is the cast. And I don't think 
> that there was a final conclusion. I am not really convinced that this should 
> be part of batman-adv. Just look at include/linux/kernel.h for similar 
> functionality (but with predefined types). Maybe this would be the correct 
> position for such a macro? (I don't know it... just thinking out loud).

Might be a good idea to send it to the kernel ml, but as usual, I think
we should first include it in the batman-adv code (am I wrong or we are
still waiting for seq_before/after to be included somewhere?).

But I agree with you, I should also send this patch to the kerel ml.

Cheers,


-- 
Antonio Quartulli

..each of us alone is worth nothing..
Ernesto "Che" Guevara ☭

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

* Re: [B.A.T.M.A.N.] [PATCH] batman-adv: add biggest_unsigned_int(x) macro
  2011-11-23 10:35 [B.A.T.M.A.N.] [PATCH] batman-adv: add biggest_unsigned_int(x) macro Antonio Quartulli
  2011-11-25  1:08 ` Marek Lindner
@ 2012-02-11 11:03 ` Marek Lindner
  1 sibling, 0 replies; 5+ messages in thread
From: Marek Lindner @ 2012-02-11 11:03 UTC (permalink / raw)
  To: The list for a Better Approach To Mobile Ad-hoc Networking

On Wednesday, November 23, 2011 18:35:44 Antonio Quartulli wrote:
> 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

Applied in revision 9c7df12.

Thanks,
Marek

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

end of thread, other threads:[~2012-02-11 11:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-23 10:35 [B.A.T.M.A.N.] [PATCH] batman-adv: add biggest_unsigned_int(x) macro Antonio Quartulli
2011-11-25  1:08 ` Marek Lindner
2011-11-25  8:50   ` Sven Eckelmann
2011-11-25 10:53     ` Antonio Quartulli
2012-02-11 11:03 ` Marek Lindner

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