All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: Christian Schoenebeck <qemu_oss@crudebyte.com>, qemu-devel@nongnu.org
Cc: Greg Kurz <groug@kaod.org>
Subject: Re: [PATCH 2/5] qemu/qarray.h: weak scalar type check in QARRAY_CREATE()
Date: Sat, 21 Aug 2021 21:11:58 -0700	[thread overview]
Message-ID: <85cd9b4b-9137-d4c8-a12e-79d6e5790a36@linaro.org> (raw)
In-Reply-To: <a3f07198ba9e12b45ef38b45fa543e9b597ee70f.1629578875.git.qemu_oss@crudebyte.com>

On 8/21/21 1:30 PM, Christian Schoenebeck wrote:
> Unfortunately something like
> 
>    _Static_assert(typeof(a) == typeof(b), "type mismatch");
> 
> is currently not suported by C. So for the time being at least
> check that the size of the scalar types match at compile time.

Did you try
_Static_assert(__builtin_types_compatible_p(X, Y), "type mismatch");


r~

> 
> Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
> ---
>   include/qemu/qarray.h | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> diff --git a/include/qemu/qarray.h b/include/qemu/qarray.h
> index 230a556e81..2cb8656c5d 100644
> --- a/include/qemu/qarray.h
> +++ b/include/qemu/qarray.h
> @@ -27,6 +27,8 @@
>   #ifndef QEMU_QARRAY_H
>   #define QEMU_QARRAY_H
>   
> +#include "qemu/compiler.h"
> +
>   /**
>    * QArray provides a mechanism to access arrays in common C-style (e.g. by
>    * square bracket [] operator) in conjunction with reference variables that
> @@ -143,6 +145,10 @@
>    * @param len - amount of array elements to be allocated immediately
>    */
>   #define QARRAY_CREATE(scalar_type, auto_var, len) \
> +    QEMU_BUILD_BUG_MSG( \
> +        sizeof(scalar_type) != sizeof(*auto_var), \
> +        "QArray scalar type mismatch" \
> +    ); \
>       qarray_create_##scalar_type((&auto_var), len)
>   
>   #endif /* QEMU_QARRAY_H */
> 



  reply	other threads:[~2021-08-22  4:21 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-21 20:47 [PATCH 0/5] introduce QArray Christian Schoenebeck
2021-08-21 20:18 ` [PATCH 1/5] qemu/qarray.h: " Christian Schoenebeck
2021-08-22 12:39   ` Christian Schoenebeck
2021-08-21 20:30 ` [PATCH 2/5] qemu/qarray.h: weak scalar type check in QARRAY_CREATE() Christian Schoenebeck
2021-08-22  4:11   ` Richard Henderson [this message]
2021-08-22 12:16     ` Christian Schoenebeck
2021-08-21 20:35 ` [PATCH 3/5] 9pfs: make V9fsString usable via QArray API Christian Schoenebeck
2021-08-21 20:37 ` [PATCH 4/5] 9pfs: make V9fsPath " Christian Schoenebeck
2021-08-21 20:39 ` [PATCH 5/5] 9pfs: use QArray in v9fs_walk() Christian Schoenebeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=85cd9b4b-9137-d4c8-a12e-79d6e5790a36@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=groug@kaod.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu_oss@crudebyte.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.