Some interesting novice questions from a novice guy

John Stanley stanley at phoenix.com
Sun Oct 28 10:41:56 AEST 1990


dhesi%cirrusl at oliveb.ATC.olivetti.com (Rahul Dhesi) writes:

> I know I'm not a C guru, and maybe I'm the only one here who gets
> confused by autoincrement-right-after-dereferencing, but I have always
> hated that "continue" statement, because it bothers my intuition.  I
> have always been taught that "continue" means "That's all right, don't
> mind me, just keep on doing what you were doing before I interrupted
> you."  But the C meaning of "continue" (not to be confused with the
> Fortran meaning of "CONTINUE") is more like: "Hey you!  Just what the
> heck do you think you are doing?  Stop that right now!  Go back to the
> beginning and do it all over again, and try to do it right this time!"
> 
   Your problems are 1) a fatal overdose of anthropomorphism and 2) a
personally concocted definition of "continue" that does not match the
real world.

   Computers are (relatively) simple machines. They do not respond to
"Hey, you!". They do not think. They are unlike humans in that if they
"try" the same instructions again, they will get the same answer.  If the
answer is not right it is either because the hardware is faulty, in which
case you should take the computer to the repair shop, or because YOU
programmed it wrong, and YOU should be taken to the repair shop.

   Your problem with anthropomorphism leads to a crocked definition of
"continue". The correct definition of "continue", in the C language
context, is "go to the top of the smallest enclosing while, do, or for."
There is no "thinking", no "try to do it right". Certainly no "Hey, you!"
Since you ignore the standard definition, I wonder what other language
elements you are confused by. Do you also choose to use only the algebraic
definition of "=" as "is equal to"? I bet a statement like "a=a+2;" really
drives you around the bend.

> Consider:
> 
> 	while(*foo++) {
>            Hey you!  Just what the heck do you think you are
>            doing?  Stop that right now!  Go back to the
>            beginning and do it all over again, and try to do
>            it right this time!
>         }
> 
   No, thank you. You consider:

	while (*foo++) {
		go to the top of the smallest enclosing while, do
		or for.
	}

> I guess part of the problem is the cognitive dissonance (Hah!  I bet
> you thought I didn't know anything about music!) 

   I still have no proof you know anything about music. It is a well known
fact that Leonard Bernstein was a quiche eater who programmed only in
Pascal. Yo Yo Ma uses APL.

> that I go through when
> I see a C "continue" used in the Fortran sense;  for what the
> programmer was *really* trying to say was:
> 
> 	while(*foo++)		/* very C-ish */
>            keep on going;	/* very Fortran-ish */
> 
   and when you know the REAL definition of "continue" you know that the
programmer said EXACTLY what he *really* meant, before you tried to mix in
the FORTRAN. BTW, "keep on going" is legal syntax in no FORTRAN I know of.
Is this a vendor extension? If not, how is "keep on going" FORTRAN-ish?

> The confusion just doesn't cut it for me.  So I do the good old simple
> stuff, complete with comments that a real guru wouldn't need (but I
> do):
> 
>         while (*foo != '\0')	/* find trailing null */
>            foo++;
>         foo++;			/* go past it */
> 
   At first blush, this looks like a while that might loop forever
followed by two increments of foo that are poorly indented. The comments
are visual cognitive dissonance (which has nothing to do with music). 

> (Actually, when I have to skip the rest of the loop body, more often
> than not, I put a label near the end of the loop and do a goto to it.

   Oh, no. I sense the beginning of a goto flame war.

> This way I can search for all occurrences of goto's to that label, and
> they are usually unique for a given loop.  A search for "continue", if
> I used it, would probably occur in many unrelated places in any given
> file, and I would be even more confused than I am now.)

   Just as a search for all occurances of while, if, etc. Why not search
for the comments. Those can be anything, unlike the elements of the C
language. Why twist the C code just so you can search for goto? Or do you
also avoid while's so you can search for labels?

   If you don't want to use the standard definition of the C programming
"words", either expect to be confused by it or don't read C.

"Arinth is a beautiful planet." "Oh, have you been there?"
  "Yes, but not yet." The Doctor. (TB)



More information about the Comp.lang.c mailing list