[Nut-upsdev] Re: [nut-commits] svn commit r414 - in trunk: . drivers

Arjen de Korte nut+devel at de-korte.org
Tue Apr 25 14:36:03 UTC 2006


>> > Fix C++ style declarations between statements
>> What is the reason for 'fixing' this? Constructions like these are used
>> in
>> many locations throughout the sources (not only in the drivers, but also
>> in common and server). If there is a compelling reason to change this,
>> we
>> need to do this in other parts as well. That will be quite an effort I
>> presume, so we should really consider if this is absolutely needed.
>> Personally, I don't think it is a big issue, since we would have seen
>> many
>> more complaints about this.
> There are no other instances like this.

Yes there are, quite a few actually. Take for instance
'drivers/mge-shut.c', in the function 'char_read' where the variable 'now'
is defined:

	if (FD_ISSET (upsfd, &readfs)) {
		int now = read (upsfd, bytes, size - readen);

This is essentially the same construction. Even in 'server/sstate.c' in
function 'sstate_connect' we have things like this (look in the Stable
tree, since I removed this in trunk before, because I didn't like the
clumsy construction):

	if (ret < 0) {
		time_t	now;

> Putting declarations between statements is not valid C.

That depends on which version you're speaking. In C99 this is allowed and
it seems that many drivers use them too (have a look and be just as
surprized as I was when I first came across this).

> There is a while block preceding the bad spot.

I know older compilers may choke on this, yet I wonder why it hasn't been
a problem in other locations in the tree so far. Your compiler should
choke on all these too.

Arjen




More information about the Nut-upsdev mailing list