Date: Mon, 13 Sep 2004 06:46:34 +0000 From: Dima Dorfman <dd@freebsd.org> To: Dan Lukes <dan@obluda.cz> Cc: keramida@freebsd.org Subject: Re: bin/71628: [PATCH] cleanup of the usr.sbin/rpcbind code Message-ID: <20040913064634.GA34521@trit.org> In-Reply-To: <41451B14.5050103@obluda.cz> References: <200409130100.i8D10xDG057337@freefall.freebsd.org> <20040913031253.GD42003@trit.org> <41451B14.5050103@obluda.cz>
next in thread | previous in thread | raw e-mail | index | archive | help
Dan Lukes <dan@obluda.cz> wrote:
> Dima Dorfman wrote:
> > Any initialization in the form "T v = v" invokes undefined behavior by
> > using the indeterminate value of an object. Eliminating a warning or
>
> Unless compiler documentation say other ...
> The v=v DURING DECLARATION (not later) is special case.
I looked for such an exception in C99 before my original post, but I
didn't find one. If it is indeed there, I'd appreciate a pointer--I'm
genuinely curious. In either case, if it depends on the compiler
documentation, then it sounds like implementation-defined behavior at
best, so we'd still prefer to avoid it.
> But I'm far away from pushing this way to eliminate warnings. It's no
> problem to initialise variable to constant for me (I hope those patches
> will not be rejected "because the initialisation is not necesarry as
> variable is properly initialised later")
We're not rejecting your patches, but we're making suggestions for
improving them. That the initialization is not necessary could be a
valid point in some cases; not everyone likes a defensive style, and
spurious initializations can be confusing ("is there really a case
where the initial value is used?"). It might be better to set to a
bogus value only when necessary. E.g.:
: int
: f(int a)
: {
: int i, j;
:
: i = 0;
: if (a) {
: i = 1;
: j = -1; /* Silence compiler warning. */
: } else
: j = 1;
: if (i)
: return (0);
: return (j);
: }
:
This isn't appropriate in all cases either, so use your judgement. If
you do decide to initialize it in the beginning, note that style(9)
discourages initializers. That's not a hard-and-fast rule, either.
Do I sound like a pedant yet? ;-)
Dima.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040913064634.GA34521>
