[systemd-devel] string constants vs. #defines [was: Re: [PATCH v4] udev hwdb: Support shipping pre-compiled database in system images]

Martin Pitt martin.pitt at ubuntu.com
Sun Oct 26 04:51:13 PDT 2014


Hello all,

Zbigniew Jędrzejewski-Szmek [2014-10-25 21:51 +0200]:
> Looks fine and push-worthy. Two minor nitpicks below, feel free
> to fix up before pushing or ignore as you see fit.

Michael raised the question about the option name. I'll wait another
day or two for responses (no time today/flight back home until
tomorrow).

> > +static const char hwdb_bin_paths[] =
> > +    "/etc/udev/hwdb.bin\0"
> > +    UDEVLIBEXECDIR "/hwdb.bin\0";
> Actually we don't need to define a variable for this, a #define would be enough.

Are #defines actually preferred in systemd's code style/conventions?
Personally I prefer "proper" constants, as they are more type safe and
less magic, and presumably string constants will end up in the same
place in the ELF anyway? Using #defines potentially duplicates the
strings too, although I suspect gcc to be clever enough to
de-duplicate identical string constants in the source. Is there any
downside to using static constants?

> Parens after NULSTR_FOREACH are not necessary.

Ack, will change that.

Thanks,

Martin
-- 
Martin Pitt                        | http://www.piware.de
Ubuntu Developer (www.ubuntu.com)  | Debian Developer  (www.debian.org)


More information about the systemd-devel mailing list