Re: [sharutils-4.11.1] Compilation warnings

Bruce Korb <[email protected]>
Newsgroups gmane.comp.gnu.utils.bugs
Message-ID <[email protected]>
On 12/06/12 16:29, Eric Blake wrote:
> You can also shut up the compiler by doing tricks like
>  strstr((const char *)expr, "")
> although I'm not sure they are worth it.

For other applications, I use C:

  #define C(_t, _v)  ((_t)(void *)(_v))

but here I will just directly add the dual layered casting because
it comes from text that gets inserted into other people's programs.

WRT:  using "%lu" for uint64_t formatting:

> ... The only portable solution here is to cast to '[u]intmax_t'.

What is the correct formatting element?  I can't quite figure that out.
If it is variable (i.e. sometimes "%lu" and sometimes "%llu"), I'm
still hosed.  Maybe just cast it to "unsigned int" and print the wrong
value on 16 bit platforms with 32 bit pids. :)

WRT: unused return value

> To warn you that you are blatantly ignoring the chance of failure.

If I've cast it to void, then it is pretty likely I am very much not
interested in what the compiler has to say:

>> If the command succeeds, cool.  If not, there's nothing I can do about it but ignore it.

> Then use the gnulib module ignore-value,

Yep.  Paul mentioned it, too.

>  ignore_value(system(fil_name))
> if you really are absolutely positive that there is no reasonable
> message to write to stderr if the command fails to run.  But I suspect
> that you really have a bug, and SHOULD be caring about system() failure.

I am certain there is nothing reasonable to do.

>> Consequently, the value is valueless.  If the compiler is going to complain about
>> an unused value when that value is explicitly cast to void, then it is a compiler bug.
> 
> Yes, we (aka gnulib writers) have argued that point with gcc developers
> in the past, and the gcc guys argued back that the GNU Coding Standards
> discourage cast-to-void and so their choice to not treat cast-to-void as

I had guessed that was the case.  The GCC guys violate a different principle
that I put above "GNU Coding Standards":  the programmer knows better than
the tool.  Any tool insisting that it knows better than a user explicitly
saying, "I want to use it this way" is wrong.  Period.  But I'm not quite
Quixotic enough to go charging off on that one again. :)

> Besides, ignore_value(system(foo)) does look better than
> (void)system(foo),

different people have different senses of aesthetics.
Anyway, very long story short, I'll add in the ignore-value module.
Thank you!  Regards, Bruce
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.