From: muvarov [mailto:notificati...@github.com] 
Sent: Tuesday, October 17, 2017 3:01 AM
To: Linaro/odp <o...@noreply.github.com>
Cc: Savolainen, Petri (Nokia - FI/Espoo) <petri.savolai...@nokia.com>; Author 
<aut...@noreply.github.com>
Subject: Re: [Linaro/odp] [PATCH API-NEXT v1] api: pool subparameters (#234)

From: Bill Fischofer 
 On Mon, Oct 16, 2017 at 8:00 AM, Github ODP bot  wrote:
> From: Petri Savolainen 
>
> Remove anonymous union from pool parameter structure.
> Union makes it impossible to initialize parameters per
> pool type (use other values than all zeros). This change
> is not visible to applications (union was anonymous).

The reason for the union was to reduce the size of the
odp_pool_param_t. I'm not sure I understand the remark about making
initializations impossible. Pool parameters are initialized to their
default values via the odp_pool_param_init() API. Failure to use this
API exposes the application to portability issues as different
implementations may have different default values. If the use of
anonymous unions discourages attempts to have static copies of
odp_pool_param_t variables, so much the better.


odp_pool_param_init() does not include type. Union cannot have multiple 
(overlapping) default values:

typedef union {
  // default value is 3 in the API spec
  int a;

  // default value is 7 in the API spec
  int b;

  // default value is 0 in the API spec
  int c;
} foo_t;

foo_t foo;

init_foot(foo_t *foo) {
    memset(&foo, 0, sizeof(foo_t));

    // Which default we now choose, a or b ?
    // Whichever we choose conflicts the spec of the other one.
    foo->a = 3;
    //foo->b = 7;
}


Struct can be init always correctly, without knowing the type beforehand. This 
is backward compatible as init_foo() prototype  and applications do not change.

typedef struct {
  // default value is 3 in the API spec
  int a;

  // default value is 7 in the API spec
  int b;

  // default value is 0 in the API spec
  int c;
} foo_t;

foo_t foo;

init_foot(foo_t *foo) {
    memset(&foo, 0, sizeof
    foo->a = 3;
    foo->b = 7;
}


-Petri

Reply via email to