[ovs-dev] [PATCH] Fully initialize structures to accomodate non C99 compilers.

Linda Sun lsun at vmware.com
Wed Jan 29 19:32:03 UTC 2014


Microsoft support seems to indicate that it always initializes the first member of the union.

Linda

----- Original Message -----
From: "Ben Pfaff" <blp at nicira.com>
To: "Linda Sun" <lsun at vmware.com>
Cc: dev at openvswitch.org
Sent: Wednesday, January 29, 2014 11:22:18 AM
Subject: Re: [ovs-dev] [PATCH] Fully initialize structures to accomodate non C99 compilers.

I don't see how those work with any vintage of C compiler.  You can't
just initialize any member of a union and expect the compiler to guess
which one you mean.

On Wed, Jan 29, 2014 at 11:18:24AM -0800, Linda Sun wrote:
> ---
>  lib/ovsdb-types.h |   20 ++++++++------------
>  1 file changed, 8 insertions(+), 12 deletions(-)
> 
> diff --git a/lib/ovsdb-types.h b/lib/ovsdb-types.h
> index efd83a7..d3aa262 100644
> --- a/lib/ovsdb-types.h
> +++ b/lib/ovsdb-types.h
> @@ -70,8 +70,8 @@ struct ovsdb_base_type {
>          /* No constraints for Boolean types. */
>  
>          struct ovsdb_string_constraints {
> -            unsigned int minLen; /* minLength or 0. */
> -            unsigned int maxLen; /* maxLength or UINT_MAX. */
> +            uint64_t minLen; /* minLength or 0. */
> +            uint64_t maxLen; /* maxLength or UINT_MAX. */
>          } string;
>  
>          struct ovsdb_uuid_constraints {
> @@ -82,16 +82,12 @@ struct ovsdb_base_type {
>      } u;
>  };
>  
> -#define OVSDB_BASE_VOID_INIT    { .type = OVSDB_TYPE_VOID }
> -#define OVSDB_BASE_INTEGER_INIT { .type = OVSDB_TYPE_INTEGER,           \
> -                                  .u.integer = { INT64_MIN, INT64_MAX } }
> -#define OVSDB_BASE_REAL_INIT    { .type = OVSDB_TYPE_REAL,          \
> -                                  .u.real = { -DBL_MAX, DBL_MAX } }
> -#define OVSDB_BASE_BOOLEAN_INIT { .type = OVSDB_TYPE_BOOLEAN }
> -#define OVSDB_BASE_STRING_INIT  { .type = OVSDB_TYPE_STRING,    \
> -                                  .u.string = { 0, UINT_MAX } }
> -#define OVSDB_BASE_UUID_INIT    { .type = OVSDB_TYPE_UUID,      \
> -                                  .u.uuid = { NULL, NULL, 0 } }
> +#define OVSDB_BASE_VOID_INIT    {OVSDB_TYPE_VOID, NULL, {0, 0}}
> +#define OVSDB_BASE_INTEGER_INIT {OVSDB_TYPE_INTEGER, NULL, {INT64_MIN, INT64_MAX}}
> +#define OVSDB_BASE_REAL_INIT    {OVSDB_TYPE_REAL, NULL, {-DBL_MAX, DBL_MAX}}
> +#define OVSDB_BASE_BOOLEAN_INIT {OVSDB_TYPE_BOOLEAN, NULL, {0, 0}}
> +#define OVSDB_BASE_STRING_INIT  {OVSDB_TYPE_STRING, NULL, {0, UINT_MAX}}
> +#define OVSDB_BASE_UUID_INIT    {OVSDB_TYPE_UUID, NULL, {0, 0}}
>  
>  void ovsdb_base_type_init(struct ovsdb_base_type *, enum ovsdb_atomic_type);
>  void ovsdb_base_type_clone(struct ovsdb_base_type *,
> -- 
> 1.7.9.5
> 
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> https://urldefense.proofpoint.com/v1/url?u=http://openvswitch.org/mailman/listinfo/dev&k=oIvRg1%2BdGAgOoM1BIlLLqw%3D%3D%0A&r=0mp263sOpVS3FERoXOmmtg%3D%3D%0A&m=52M5lJHBxSEbBgELwRbVRlv19ixdBh9GtSurlp%2Fzhsc%3D%0A&s=1aec666d527e6dd50b24a0803e30adedb02fbd5c29b6299d07e2ed41393ad817



More information about the dev mailing list