[PATCH phosphor-host-ipmid] Implement Network Override
Patrick Williams
patrick at stwcx.xyz
Thu Jun 9 11:14:06 AEST 2016
On Tue, Jun 07, 2016 at 11:29:57AM +1000, Cyril Bur wrote:
> > +struct host_network_config_t {
> > + string ipaddress;
> > + string prefix;
> > + string gateway;
> > + string macaddress;
> > + string isDHCP;
> > +
> > + host_network_config_t()
> > + {
> > + ipaddress = "";
> > + prefix = "";
> > + gateway = "";
> > + macaddress = "";
> > + isDHCP = "";
> > + }
>
> Admittedly I don't do c++, is this c++? Do c++ programmers recommend this?
>
No, they don't.
In modern C++, this would have accomplished the same thing more
efficiently:
host_network_config_t() = default;
If you want to be explicit about initializing the strings to empty, this
is preferred:
host_network_config_t() : ipaddress(""), prefix("") ... {}
or better yet...
host_network_config_t() : ipaddress(""s), prefix(""s) ... {}
Both of these are better than assign-to-empty because it avoids a
copy-constructor (C++04) or move-constructor (C++11) from the temporary.
Neither of these two options are actually preferred though. Since,
'string() == ""', there really is no reason to do any explicit
construction. Internally 'string()' likely results in "string->data"
being NULL while 'string("")' likely results in the data pointer being a
zero-sized malloc. Again, if you prefer to be explicit, this does the
same job:
host_network_config_t() : ipaddress(), prefix() ... {}
> > +
> > + uint8_t data[SIZE_BOOT_OPTION]={0x80,0x21, 0x70 ,0x62 ,0x21,0x00 ,0x01 ,0x06 ,0x04};
>
> uint8_t data[SIZE_BOOT_OPTION] = {0x80, 0x21, 0x70, 0x62, 0x21, 0x00, 0x01,
> 0x06, 0x04};
>
If we're going to use C++, preferred way is:
std::array<uint8_t, SIZE_BOOT_OPTION> data {0x80, 0x21, ...};
This will do an in-place initialization of a type-safe and
bounds-checked array.
--
Patrick Williams
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.ozlabs.org/pipermail/openbmc/attachments/20160608/4570a322/attachment.sig>
More information about the openbmc
mailing list