diff mbox

linux-generic: debug: enable helper use from c++ programs

Message ID 20170125014626.28667-1-bill.fischofer@linaro.org
State New
Headers show

Commit Message

Bill Fischofer Jan. 25, 2017, 1:46 a.m. UTC
The ODP_STATIC_ASSERT() macro expands to _Static_assert(), however when
used in C++ programs this needs to expand to static_assert().

This resolves Bug https://bugs.linaro.org/show_bug.cgi?id=2852

Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>

---
 platform/linux-generic/include/odp/api/debug.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

-- 
2.9.3

Comments

Maxim Uvarov Jan. 25, 2017, 6:57 a.m. UTC | #1
On 25 January 2017 at 04:46, Bill Fischofer <bill.fischofer@linaro.org>
wrote:

> The ODP_STATIC_ASSERT() macro expands to _Static_assert(), however when

> used in C++ programs this needs to expand to static_assert().

>

> This resolves Bug https://bugs.linaro.org/show_bug.cgi?id=2852

>

> Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>

> ---

>  platform/linux-generic/include/odp/api/debug.h | 6 ++++--

>  1 file changed, 4 insertions(+), 2 deletions(-)

>

> diff --git a/platform/linux-generic/include/odp/api/debug.h

> b/platform/linux-generic/include/odp/api/debug.h

> index 7db1433..19659a9 100644

> --- a/platform/linux-generic/include/odp/api/debug.h

> +++ b/platform/linux-generic/include/odp/api/debug.h

> @@ -39,9 +39,11 @@ extern "C" {

>   * if condition 'cond' is false. Macro definition is empty when compiler

> is not

>   * supported or the compiler does not support static assertion.

>   */

> -#define ODP_STATIC_ASSERT(cond, msg)  _Static_assert(cond, msg)

> +#ifndef __cplusplus

> +#define ODP_STATIC_ASSERT(cond, msg) _Static_assert(cond, msg)

>

> -#ifdef __cplusplus

> +#else

> +#define ODP_STATIC_ASSERT(cond, msg) static_assert(cond, msg)

>  }

>  #endif

>

> --

> 2.9.3

>



why ifndef is used instead of ifdef? I think ifdef is more readable.

Maxim.
Bill Fischofer Jan. 25, 2017, 12:29 p.m. UTC | #2
On Wed, Jan 25, 2017 at 12:57 AM, Maxim Uvarov <maxim.uvarov@linaro.org> wrote:
>

>

> On 25 January 2017 at 04:46, Bill Fischofer <bill.fischofer@linaro.org>

> wrote:

>>

>> The ODP_STATIC_ASSERT() macro expands to _Static_assert(), however when

>> used in C++ programs this needs to expand to static_assert().

>>

>> This resolves Bug https://bugs.linaro.org/show_bug.cgi?id=2852

>>

>> Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>

>> ---

>>  platform/linux-generic/include/odp/api/debug.h | 6 ++++--

>>  1 file changed, 4 insertions(+), 2 deletions(-)

>>

>> diff --git a/platform/linux-generic/include/odp/api/debug.h

>> b/platform/linux-generic/include/odp/api/debug.h

>> index 7db1433..19659a9 100644

>> --- a/platform/linux-generic/include/odp/api/debug.h

>> +++ b/platform/linux-generic/include/odp/api/debug.h

>> @@ -39,9 +39,11 @@ extern "C" {

>>   * if condition 'cond' is false. Macro definition is empty when compiler

>> is not

>>   * supported or the compiler does not support static assertion.

>>   */

>> -#define ODP_STATIC_ASSERT(cond, msg)  _Static_assert(cond, msg)

>> +#ifndef __cplusplus

>> +#define ODP_STATIC_ASSERT(cond, msg) _Static_assert(cond, msg)

>>

>> -#ifdef __cplusplus

>> +#else

>> +#define ODP_STATIC_ASSERT(cond, msg) static_assert(cond, msg)

>>  }

>>  #endif

>>

>> --

>> 2.9.3

>

>

>

> why ifndef is used instead of ifdef? I think ifdef is more readable.


Because it's part of the bracketing around the __cplusplus guard. The
alternative would be to have two separate guards:

#ifdef __cplusplus
#define ODP_STATIC_ASSERT(cond, msg) static_assert(cond, msg)
#else
#define ODP_STATIC_ASSERT(cond, msg) _Static_assert(cond, msg)
#endif

#ifdef __cplusplus
}
#endif

which seemed more cumbersome to me. If you really object to this form
I can change it, but this seamed cleaner.

>

> Maxim.

>

>
Maxim Uvarov Jan. 25, 2017, 12:38 p.m. UTC | #3
On 01/25/17 15:29, Bill Fischofer wrote:
> On Wed, Jan 25, 2017 at 12:57 AM, Maxim Uvarov <maxim.uvarov@linaro.org> wrote:

>>

>>

>> On 25 January 2017 at 04:46, Bill Fischofer <bill.fischofer@linaro.org>

>> wrote:

>>>

>>> The ODP_STATIC_ASSERT() macro expands to _Static_assert(), however when

>>> used in C++ programs this needs to expand to static_assert().

>>>

>>> This resolves Bug https://bugs.linaro.org/show_bug.cgi?id=2852

>>>

>>> Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>

>>> ---

>>>  platform/linux-generic/include/odp/api/debug.h | 6 ++++--

>>>  1 file changed, 4 insertions(+), 2 deletions(-)

>>>

>>> diff --git a/platform/linux-generic/include/odp/api/debug.h

>>> b/platform/linux-generic/include/odp/api/debug.h

>>> index 7db1433..19659a9 100644

>>> --- a/platform/linux-generic/include/odp/api/debug.h

>>> +++ b/platform/linux-generic/include/odp/api/debug.h

>>> @@ -39,9 +39,11 @@ extern "C" {

>>>   * if condition 'cond' is false. Macro definition is empty when compiler

>>> is not

>>>   * supported or the compiler does not support static assertion.

>>>   */

>>> -#define ODP_STATIC_ASSERT(cond, msg)  _Static_assert(cond, msg)

>>> +#ifndef __cplusplus

>>> +#define ODP_STATIC_ASSERT(cond, msg) _Static_assert(cond, msg)

>>>

>>> -#ifdef __cplusplus

>>> +#else

>>> +#define ODP_STATIC_ASSERT(cond, msg) static_assert(cond, msg)

>>>  }

>>>  #endif

>>>

>>> --

>>> 2.9.3

>>

>>

>>

>> why ifndef is used instead of ifdef? I think ifdef is more readable.

> 

> Because it's part of the bracketing around the __cplusplus guard. The

> alternative would be to have two separate guards:

> 

> #ifdef __cplusplus

> #define ODP_STATIC_ASSERT(cond, msg) static_assert(cond, msg)

> #else

> #define ODP_STATIC_ASSERT(cond, msg) _Static_assert(cond, msg)

> #endif

> 

> #ifdef __cplusplus

> }

> #endif

> 

> which seemed more cumbersome to me. If you really object to this form

> I can change it, but this seamed cleaner.



ah, ok. did not look to code itself and from patch is wasn't clear.

> 

>>

>> Maxim.

>>

>>
diff mbox

Patch

diff --git a/platform/linux-generic/include/odp/api/debug.h b/platform/linux-generic/include/odp/api/debug.h
index 7db1433..19659a9 100644
--- a/platform/linux-generic/include/odp/api/debug.h
+++ b/platform/linux-generic/include/odp/api/debug.h
@@ -39,9 +39,11 @@  extern "C" {
  * if condition 'cond' is false. Macro definition is empty when compiler is not
  * supported or the compiler does not support static assertion.
  */
-#define ODP_STATIC_ASSERT(cond, msg)  _Static_assert(cond, msg)
+#ifndef __cplusplus
+#define ODP_STATIC_ASSERT(cond, msg) _Static_assert(cond, msg)
 
-#ifdef __cplusplus
+#else
+#define ODP_STATIC_ASSERT(cond, msg) static_assert(cond, msg)
 }
 #endif