diff mbox

[edk2,05/47] MdePkg/Include/Base.h: introduce the ARRAY_SIZE() function-like macro

Message ID 20161026190504.9888-6-lersek@redhat.com
State Accepted
Commit c3ead528287db5ae779fc7ca00f935516d685c2a
Headers show

Commit Message

Laszlo Ersek Oct. 26, 2016, 7:04 p.m. UTC
Several modules use ARRAY_SIZE() already; centralize the definition. (The
module-specific macro definitions are guarded by #ifndef directives at
this point.)

Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Cecil Sheng <cecil.sheng@hpe.com>
Cc: Chao Zhang <chao.b.zhang@intel.com>
Cc: Dandan Bi <dandan.bi@intel.com>
Cc: Daryl McDaniel <edk2-lists@mc2research.org>
Cc: David Wei <david.wei@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Feng Tian <feng.tian@intel.com>
Cc: Gary Lin <glin@suse.com>
Cc: Jaben Carsey <jaben.carsey@intel.com>
Cc: Jeff Fan <jeff.fan@intel.com>
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Siyuan Fu <siyuan.fu@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Tim He <tim.he@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>

---
 MdePkg/Include/Base.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)

-- 
2.9.2


_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Comments

Kinney, Michael D Oct. 26, 2016, 10:13 p.m. UTC | #1
Hi Laszlo,

One comment inline below.

Mike

> -----Original Message-----

> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Laszlo Ersek

> Sent: Wednesday, October 26, 2016 12:04 PM

> To: edk2-devel-01 <edk2-devel@ml01.01.org>

> Cc: Ni, Ruiyu <ruiyu.ni@intel.com>; Tim He <tim.he@intel.com>; Tian, Feng

> <feng.tian@intel.com>; Kinney, Michael D <michael.d.kinney@intel.com>; Dong, Eric

> <eric.dong@intel.com>; Cecil Sheng <cecil.sheng@hpe.com>; Ard Biesheuvel

> <ard.biesheuvel@linaro.org>; Justen, Jordan L <jordan.l.justen@intel.com>; Gao, Liming

> <liming.gao@intel.com>; Bi, Dandan <dandan.bi@intel.com>; Wu, Jiaxin

> <jiaxin.wu@intel.com>; Gary Lin <glin@suse.com>; Zeng, Star <star.zeng@intel.com>;

> Daryl McDaniel <edk2-lists@mc2research.org>; Carsey, Jaben <jaben.carsey@intel.com>;

> Fu, Siyuan <siyuan.fu@intel.com>; Fan, Jeff <jeff.fan@intel.com>; Zhang, Chao B

> <chao.b.zhang@intel.com>; Wei, David <david.wei@intel.com>

> Subject: [edk2] [PATCH 05/47] MdePkg/Include/Base.h: introduce the ARRAY_SIZE()

> function-like macro

> 

> Several modules use ARRAY_SIZE() already; centralize the definition. (The

> module-specific macro definitions are guarded by #ifndef directives at

> this point.)

> 

> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>

> Cc: Cecil Sheng <cecil.sheng@hpe.com>

> Cc: Chao Zhang <chao.b.zhang@intel.com>

> Cc: Dandan Bi <dandan.bi@intel.com>

> Cc: Daryl McDaniel <edk2-lists@mc2research.org>

> Cc: David Wei <david.wei@intel.com>

> Cc: Eric Dong <eric.dong@intel.com>

> Cc: Feng Tian <feng.tian@intel.com>

> Cc: Gary Lin <glin@suse.com>

> Cc: Jaben Carsey <jaben.carsey@intel.com>

> Cc: Jeff Fan <jeff.fan@intel.com>

> Cc: Jiaxin Wu <jiaxin.wu@intel.com>

> Cc: Jordan Justen <jordan.l.justen@intel.com>

> Cc: Liming Gao <liming.gao@intel.com>

> Cc: Michael D Kinney <michael.d.kinney@intel.com>

> Cc: Ruiyu Ni <ruiyu.ni@intel.com>

> Cc: Siyuan Fu <siyuan.fu@intel.com>

> Cc: Star Zeng <star.zeng@intel.com>

> Cc: Tim He <tim.he@intel.com>

> Contributed-under: TianoCore Contribution Agreement 1.0

> Signed-off-by: Laszlo Ersek <lersek@redhat.com>

> ---

>  MdePkg/Include/Base.h | 13 +++++++++++++

>  1 file changed, 13 insertions(+)

> 

> diff --git a/MdePkg/Include/Base.h b/MdePkg/Include/Base.h

> index c66614846488..8bdb257e37bd 100644

> --- a/MdePkg/Include/Base.h

> +++ b/MdePkg/Include/Base.h

> @@ -1211,5 +1211,18 @@ typedef UINTN RETURN_STATUS;

>    #define RETURN_ADDRESS(L)     ((VOID *) 0)

>  #endif

> 

> +/**

> +  Return the number of elements in an array.

> +

> +  @param  Array  An object of array type. Array is only used as an argument to

> +                 the sizeof operator, therefore Array is never evaluated. The

> +                 caller is responsible for ensuring that Array's type is not

> +                 incomplete; that is, Array must have known constant size.

> +

> +  @return The number of elements in Array. The result has type UINTN.

> +

> +**/

> +#define ARRAY_SIZE(Array) (sizeof (Array) / sizeof (Array)[0])

 
I think adding one extra set of () makes this clearer:

#define ARRAY_SIZE(Array) (sizeof (Array) / sizeof ((Array)[0]))

> +

>  #endif

> 

> --

> 2.9.2

> 

> 

> _______________________________________________

> edk2-devel mailing list

> edk2-devel@lists.01.org

> https://lists.01.org/mailman/listinfo/edk2-devel

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Laszlo Ersek Oct. 26, 2016, 10:25 p.m. UTC | #2
On 10/27/16 00:13, Kinney, Michael D wrote:
> Hi Laszlo,

> 

> One comment inline below.

> 

> Mike

> 

>> -----Original Message-----

>> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Laszlo Ersek

>> Sent: Wednesday, October 26, 2016 12:04 PM

>> To: edk2-devel-01 <edk2-devel@ml01.01.org>

>> Cc: Ni, Ruiyu <ruiyu.ni@intel.com>; Tim He <tim.he@intel.com>; Tian, Feng

>> <feng.tian@intel.com>; Kinney, Michael D <michael.d.kinney@intel.com>; Dong, Eric

>> <eric.dong@intel.com>; Cecil Sheng <cecil.sheng@hpe.com>; Ard Biesheuvel

>> <ard.biesheuvel@linaro.org>; Justen, Jordan L <jordan.l.justen@intel.com>; Gao, Liming

>> <liming.gao@intel.com>; Bi, Dandan <dandan.bi@intel.com>; Wu, Jiaxin

>> <jiaxin.wu@intel.com>; Gary Lin <glin@suse.com>; Zeng, Star <star.zeng@intel.com>;

>> Daryl McDaniel <edk2-lists@mc2research.org>; Carsey, Jaben <jaben.carsey@intel.com>;

>> Fu, Siyuan <siyuan.fu@intel.com>; Fan, Jeff <jeff.fan@intel.com>; Zhang, Chao B

>> <chao.b.zhang@intel.com>; Wei, David <david.wei@intel.com>

>> Subject: [edk2] [PATCH 05/47] MdePkg/Include/Base.h: introduce the ARRAY_SIZE()

>> function-like macro

>>

>> Several modules use ARRAY_SIZE() already; centralize the definition. (The

>> module-specific macro definitions are guarded by #ifndef directives at

>> this point.)

>>

>> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>

>> Cc: Cecil Sheng <cecil.sheng@hpe.com>

>> Cc: Chao Zhang <chao.b.zhang@intel.com>

>> Cc: Dandan Bi <dandan.bi@intel.com>

>> Cc: Daryl McDaniel <edk2-lists@mc2research.org>

>> Cc: David Wei <david.wei@intel.com>

>> Cc: Eric Dong <eric.dong@intel.com>

>> Cc: Feng Tian <feng.tian@intel.com>

>> Cc: Gary Lin <glin@suse.com>

>> Cc: Jaben Carsey <jaben.carsey@intel.com>

>> Cc: Jeff Fan <jeff.fan@intel.com>

>> Cc: Jiaxin Wu <jiaxin.wu@intel.com>

>> Cc: Jordan Justen <jordan.l.justen@intel.com>

>> Cc: Liming Gao <liming.gao@intel.com>

>> Cc: Michael D Kinney <michael.d.kinney@intel.com>

>> Cc: Ruiyu Ni <ruiyu.ni@intel.com>

>> Cc: Siyuan Fu <siyuan.fu@intel.com>

>> Cc: Star Zeng <star.zeng@intel.com>

>> Cc: Tim He <tim.he@intel.com>

>> Contributed-under: TianoCore Contribution Agreement 1.0

>> Signed-off-by: Laszlo Ersek <lersek@redhat.com>

>> ---

>>  MdePkg/Include/Base.h | 13 +++++++++++++

>>  1 file changed, 13 insertions(+)

>>

>> diff --git a/MdePkg/Include/Base.h b/MdePkg/Include/Base.h

>> index c66614846488..8bdb257e37bd 100644

>> --- a/MdePkg/Include/Base.h

>> +++ b/MdePkg/Include/Base.h

>> @@ -1211,5 +1211,18 @@ typedef UINTN RETURN_STATUS;

>>    #define RETURN_ADDRESS(L)     ((VOID *) 0)

>>  #endif

>>

>> +/**

>> +  Return the number of elements in an array.

>> +

>> +  @param  Array  An object of array type. Array is only used as an argument to

>> +                 the sizeof operator, therefore Array is never evaluated. The

>> +                 caller is responsible for ensuring that Array's type is not

>> +                 incomplete; that is, Array must have known constant size.

>> +

>> +  @return The number of elements in Array. The result has type UINTN.

>> +

>> +**/

>> +#define ARRAY_SIZE(Array) (sizeof (Array) / sizeof (Array)[0])

>  

> I think adding one extra set of () makes this clearer:

> 

> #define ARRAY_SIZE(Array) (sizeof (Array) / sizeof ((Array)[0]))


Sure, will do.

Thanks!
Laszlo

>> +

>>  #endif

>>

>> --

>> 2.9.2

>>

>>

>> _______________________________________________

>> edk2-devel mailing list

>> edk2-devel@lists.01.org

>> https://lists.01.org/mailman/listinfo/edk2-devel


_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Kinney, Michael D Oct. 27, 2016, 2:21 a.m. UTC | #3
With that change:

Reviewed-by: Michael Kinney <michael.d.kinney@intel.com>


Mike

> -----Original Message-----

> From: Laszlo Ersek [mailto:lersek@redhat.com]

> Sent: Wednesday, October 26, 2016 3:26 PM

> To: Kinney, Michael D <michael.d.kinney@intel.com>; edk2-devel-01 <edk2-

> devel@ml01.01.org>

> Cc: Ni, Ruiyu <ruiyu.ni@intel.com>; Tim He <tim.he@intel.com>; Tian, Feng

> <feng.tian@intel.com>; Dong, Eric <eric.dong@intel.com>; Cecil Sheng

> <cecil.sheng@hpe.com>; Ard Biesheuvel <ard.biesheuvel@linaro.org>; Justen, Jordan L

> <jordan.l.justen@intel.com>; Gao, Liming <liming.gao@intel.com>; Bi, Dandan

> <dandan.bi@intel.com>; Wu, Jiaxin <jiaxin.wu@intel.com>; Gary Lin <glin@suse.com>;

> Zeng, Star <star.zeng@intel.com>; Daryl McDaniel <edk2-lists@mc2research.org>; Carsey,

> Jaben <jaben.carsey@intel.com>; Fu, Siyuan <siyuan.fu@intel.com>; Fan, Jeff

> <jeff.fan@intel.com>; Zhang, Chao B <chao.b.zhang@intel.com>; Wei, David

> <david.wei@intel.com>

> Subject: Re: [edk2] [PATCH 05/47] MdePkg/Include/Base.h: introduce the ARRAY_SIZE()

> function-like macro

> 

> On 10/27/16 00:13, Kinney, Michael D wrote:

> > Hi Laszlo,

> >

> > One comment inline below.

> >

> > Mike

> >

> >> -----Original Message-----

> >> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Laszlo Ersek

> >> Sent: Wednesday, October 26, 2016 12:04 PM

> >> To: edk2-devel-01 <edk2-devel@ml01.01.org>

> >> Cc: Ni, Ruiyu <ruiyu.ni@intel.com>; Tim He <tim.he@intel.com>; Tian, Feng

> >> <feng.tian@intel.com>; Kinney, Michael D <michael.d.kinney@intel.com>; Dong, Eric

> >> <eric.dong@intel.com>; Cecil Sheng <cecil.sheng@hpe.com>; Ard Biesheuvel

> >> <ard.biesheuvel@linaro.org>; Justen, Jordan L <jordan.l.justen@intel.com>; Gao,

> Liming

> >> <liming.gao@intel.com>; Bi, Dandan <dandan.bi@intel.com>; Wu, Jiaxin

> >> <jiaxin.wu@intel.com>; Gary Lin <glin@suse.com>; Zeng, Star <star.zeng@intel.com>;

> >> Daryl McDaniel <edk2-lists@mc2research.org>; Carsey, Jaben <jaben.carsey@intel.com>;

> >> Fu, Siyuan <siyuan.fu@intel.com>; Fan, Jeff <jeff.fan@intel.com>; Zhang, Chao B

> >> <chao.b.zhang@intel.com>; Wei, David <david.wei@intel.com>

> >> Subject: [edk2] [PATCH 05/47] MdePkg/Include/Base.h: introduce the ARRAY_SIZE()

> >> function-like macro

> >>

> >> Several modules use ARRAY_SIZE() already; centralize the definition. (The

> >> module-specific macro definitions are guarded by #ifndef directives at

> >> this point.)

> >>

> >> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>

> >> Cc: Cecil Sheng <cecil.sheng@hpe.com>

> >> Cc: Chao Zhang <chao.b.zhang@intel.com>

> >> Cc: Dandan Bi <dandan.bi@intel.com>

> >> Cc: Daryl McDaniel <edk2-lists@mc2research.org>

> >> Cc: David Wei <david.wei@intel.com>

> >> Cc: Eric Dong <eric.dong@intel.com>

> >> Cc: Feng Tian <feng.tian@intel.com>

> >> Cc: Gary Lin <glin@suse.com>

> >> Cc: Jaben Carsey <jaben.carsey@intel.com>

> >> Cc: Jeff Fan <jeff.fan@intel.com>

> >> Cc: Jiaxin Wu <jiaxin.wu@intel.com>

> >> Cc: Jordan Justen <jordan.l.justen@intel.com>

> >> Cc: Liming Gao <liming.gao@intel.com>

> >> Cc: Michael D Kinney <michael.d.kinney@intel.com>

> >> Cc: Ruiyu Ni <ruiyu.ni@intel.com>

> >> Cc: Siyuan Fu <siyuan.fu@intel.com>

> >> Cc: Star Zeng <star.zeng@intel.com>

> >> Cc: Tim He <tim.he@intel.com>

> >> Contributed-under: TianoCore Contribution Agreement 1.0

> >> Signed-off-by: Laszlo Ersek <lersek@redhat.com>

> >> ---

> >>  MdePkg/Include/Base.h | 13 +++++++++++++

> >>  1 file changed, 13 insertions(+)

> >>

> >> diff --git a/MdePkg/Include/Base.h b/MdePkg/Include/Base.h

> >> index c66614846488..8bdb257e37bd 100644

> >> --- a/MdePkg/Include/Base.h

> >> +++ b/MdePkg/Include/Base.h

> >> @@ -1211,5 +1211,18 @@ typedef UINTN RETURN_STATUS;

> >>    #define RETURN_ADDRESS(L)     ((VOID *) 0)

> >>  #endif

> >>

> >> +/**

> >> +  Return the number of elements in an array.

> >> +

> >> +  @param  Array  An object of array type. Array is only used as an argument to

> >> +                 the sizeof operator, therefore Array is never evaluated. The

> >> +                 caller is responsible for ensuring that Array's type is not

> >> +                 incomplete; that is, Array must have known constant size.

> >> +

> >> +  @return The number of elements in Array. The result has type UINTN.

> >> +

> >> +**/

> >> +#define ARRAY_SIZE(Array) (sizeof (Array) / sizeof (Array)[0])

> >

> > I think adding one extra set of () makes this clearer:

> >

> > #define ARRAY_SIZE(Array) (sizeof (Array) / sizeof ((Array)[0]))

> 

> Sure, will do.

> 

> Thanks!

> Laszlo

> 

> >> +

> >>  #endif

> >>

> >> --

> >> 2.9.2

> >>

> >>

> >> _______________________________________________

> >> edk2-devel mailing list

> >> edk2-devel@lists.01.org

> >> https://lists.01.org/mailman/listinfo/edk2-devel


_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
diff mbox

Patch

diff --git a/MdePkg/Include/Base.h b/MdePkg/Include/Base.h
index c66614846488..8bdb257e37bd 100644
--- a/MdePkg/Include/Base.h
+++ b/MdePkg/Include/Base.h
@@ -1211,5 +1211,18 @@  typedef UINTN RETURN_STATUS;
   #define RETURN_ADDRESS(L)     ((VOID *) 0)
 #endif
 
+/**
+  Return the number of elements in an array.
+
+  @param  Array  An object of array type. Array is only used as an argument to
+                 the sizeof operator, therefore Array is never evaluated. The
+                 caller is responsible for ensuring that Array's type is not
+                 incomplete; that is, Array must have known constant size.
+
+  @return The number of elements in Array. The result has type UINTN.
+
+**/
+#define ARRAY_SIZE(Array) (sizeof (Array) / sizeof (Array)[0])
+
 #endif