cygcheck exit status

Eric Blake
Wed Jul 6 14:21:00 GMT 2005

Igor Pechtchanski <pechtcha <at>> writes:
> > Because it's in a for loop, and when the first file fails but second
> > succeeds, you still want the overall command to exit with failure.
> That's the correct intent, but shouldn't it be &&= instead of &=,
> technically?

There's no such thing as &&=.  And even if there was, you wouldn't want to use 
it, because it would short-circuit running cygcheck().  The whole point of the 
boolean collector is to run the test on every file, but to remember if any of 
the tests failed.  Maybe thinking of a short-circuit in the reverse direction 
will help you understand:

ok = cygcheck (argv[i]) && ok;

But since ok is a simple boolean, short-circuiting doesn't save us any side 
effects, so we can use:

ok = cygcheck (argv[i]) & ok;

And since & is commutative, it has the same outcome as:

ok = ok & cygcheck (argv[i]);

Hence my shorthand (coreutils uses this idiom a lot, too):

ok &= cygcheck (argv[i]);

[By deMorgan's law, I could have also reversed the sense of the collector:
bool failed = false;
for (int i; ...)
  failed |= test_that_returns_true_on_failure();
return failed ? EXIT_FAILURE : EXIT_SUCCESS;

But I hate thinking in negative logic, hence my definition of cygcheck to 
return true on success.]

Eric Blake

More information about the Cygwin-patches mailing list