[comp.sources.d] Multivol dumps core?

paul@vixie.UUCP (Paul Vixie Esq) (12/15/86)

I tried to compile and use multivol today.  It compiled without incident,
but it and testdata dump core during 'make wfile'.  My debugger is hosed,
and refuses to print a stack trace, so I started looking through the code.

In testdata.c, I found:

	...
	if (no_eoln = (*argv[1] == '-' && *++argv[1] == 'n')) {
	...

Now, since C doesn't guarantee order of evaluation, this seems blatently
wrong.  I don't know neccessarily that this is the cause of my problem,
but if the rest of the code has errors like this, I don't want to bother
trying to find the cause of the core dumps.  Mission: Impossible :-), and
I refuse to accept it.

Is there an alternative to (or more recent version of) multivol?

-- 
Paul A. Vixie        {ptsfa, qantel, crash, winfree}!vixie!paul
329 Noe Street       dual!ptsfa!vixie!paul@ucbvax.Berkeley.EDU
San Francisco        nike!ptsfa!vixie!paul@seismo.CSS.GOV
CA  94116            paul@vixie.UUCP     (415) 864-7013

tsf@theory.cs.cmu.edu (Timothy Freeman) (12/16/86)

"The left operand of '&&' is fully evaluated first."

Page 181, "C a reference manual", by Harbison & Steele, 1984.  What
was it that you were saying was evaluated in an unspecified order?

Tim Freeman

Arpanet: tsf@theory.cs.cmu.edu
Uucp:    ...!seismo!theory.cs.cmu.edu!tsf

campbell@maynard.BSW.COM (Larry Campbell) (12/16/86)

In article <403@vixie.UUCP> paul@vixie.UUCP (Paul Vixie Esq) writes:
 ...
>In testdata.c, I found:
>
>	if (no_eoln = (*argv[1] == '-' && *++argv[1] == 'n')) {
>
>Now, since C doesn't guarantee order of evaluation, this seems blatently
>wrong.  I don't know neccessarily that this is the cause of my problem,
>but if the rest of the code has errors like this, I don't want to bother
>trying to find the cause of the core dumps.  Mission: Impossible :-), and
>I refuse to accept it.

You are suffering from an all too common misconception.  There are several
clearly documented operators for which the order of evaluation IS guaranteed,
and && is one of them.  I quote from section 7.11 (pg. 190) of K&R:

	Unlike &, && guarantees left-to-right evaluation;  moreover
	the second operand is not evaluated if the first operand is 0.

There may well be bugs in multivol, but the example quoted above isn't one
of them.
-- 
Larry Campbell                                The Boston Software Works, Inc.
Internet: campbell@maynard.bsw.com          120 Fulton Street, Boston MA 02109
uucp: {alliant,wjh12}!maynard!campbell              +1 617 367 6846
ARPA: campbell%maynard.uucp@harvisr.harvard.edu      MCI: LCAMPBELL

ted@blia.BLI.COM (Ted Marshall) (12/16/86)

In article <403@vixie.UUCP>, paul@vixie.UUCP (Paul Vixie Esq) writes:
> In testdata.c, I found:
> 	if (no_eoln = (*argv[1] == '-' && *++argv[1] == 'n')) {
> Now, since C doesn't guarantee order of evaluation, this seems blatently
> wrong...

Sorry, but this not wrong. Look at K&R page 19: "Expressions connected by
&& or || are evaluated left to right and it is guaranteed that evaluation
will stop as soon as the truth or falsehood is known." Of course, this
doesn't help you find the bug (I'm a VMS programmer so I'm not familiar
with multivol. Sorry.)

Ted Marshall @ Britton Lee, Inc
UUCP:   ...!ucbvax!mtxinu!blia!ted

psfales@ihlpl.UUCP (Peter Fales) (12/16/86)

> In testdata.c, I found:
> 	...
> 	if (no_eoln = (*argv[1] == '-' && *++argv[1] == 'n')) {
> 	...
> Now, since C doesn't guarantee order of evaluation, this seems blatently
> wrong.

Kerhighan & Ritchie, p. 190: "Unlike &, && guarantees left-to-right
evaluation; moreover the second operand is not evaluated if if the
first operand is 0."

Peter Fales
ihnp4!ihlpl!psfales

john@basser.oz (John Mackin) (12/17/86)

In article <403@vixie.UUCP> paul@vixie.UUCP (Paul Vixie Esq) writes:

> 	if (no_eoln = (*argv[1] == '-' && *++argv[1] == 'n')) {
> 
> Now, since C doesn't guarantee order of evaluation, this seems blatently
> wrong.  I don't know neccessarily that this is the cause of my problem,
> but if the rest of the code has errors like this, I don't want to bother
> trying to find the cause of the core dumps.

Oh dear.  Restraint, tolerance, good karma.  Remember those good
loops you flew over the dam this morning.  Deep breaths.  NOW...

Look here!  I am not going to say that multivol is well coded.
I can't comment on that, as I have never looked at its internals.
But I am MOST CERTAINLY going to say that your specific criticism
is totally incorrect, unjustified, and unwarranted, and in fact you
do not know what you are talking about.  A little knowledge, it would
seem, is a dangerous thing.

You state that ``C does not guarantee order of evaluation''.  This is
patently false.  If you look in the index of K&R, you will see "order
of evaluation" indexed in quite a few places.  The VERY FIRST PLACE IT IS
MENTIONED is on page 19, section 1.5, under "Word Counting", where it
states:

	Expressions connected by && or || are evaluated left
	to right ...

Sure sounds like a guarantee to me!

Certainly, order of evalution is undefined for many of C's operators;
you will see this if you look at some of the other places mentioned in the
index entry.  It IS defined for && and ||.

Please find out what you are talking about before you post to the net.
Thousands of people worldwide will read your articles.  If you post
misinformation, you will confuse some of them.  They may write code
which is wrong or form ideas which are wrong, due to your posted
misinformation.  Please, get it right.

John Mackin, Basser Department of Computer Science,
	     University of Sydney, Sydney, Australia

john@basser.oz.AU (john%basser.oz@SEISMO.CSS.GOV)
{seismo,hplabs,mcvax,ukc,nttlab}!munnari!basser.oz!john