Compilation of for construct in C

"S.Bharadwaj Yadavalli" <>
Mon, 25 Sep 1995 21:17:35 GMT

          From comp.compilers

Related articles
Compilation of for construct in C (S.Bharadwaj Yadavalli) (1995-09-25)
| List of all articles for this month |

Newsgroups: comp.compilers
From: "S.Bharadwaj Yadavalli" <>
Keywords: C, question, comment
Organization: Compilers Central
Date: Mon, 25 Sep 1995 21:17:35 GMT

I have a question about something I read in Coo. of ACM Sept '95
issue. Ref. pp109 in the Technical opinion section wherein the
article "More on the Programming Language C" is discussed. I
quote the portion that puzzles me:

            [...] The answer ( to why GOTO statement is dangerous as
            illustrated in the context of FOR statement) can be found
            in the study of compiler writing. Suppose you are writing
            a compiler for Fortran, or Pascal or Ada and you come to a
            FOR statement like ones mentioned ( these were indeed
            mentioned in the article previously ), and you have to
            generate machine code for it. Since machine code has only
            assignment, GOTO and conditional GOTO, you have to
            generate code with a functionality like this:

                            i := m
                      L: if i > m THEN GOTO D
                            (body of the loop)
                            i := i + 1
                            GOTO L
                      D: (next statement)

[So far so good]
Quote continues:
            But there is no question, in Fortran or Pascal or Ada, of
            requiring the user to know this is what is going on
            underneath. There is, however, in C. In fact, the general
            form of the FOR statement in C is

                            for(initialization; test_condition; increment)
                                    {body of the loop}

            and this translates directly into the generated machine language

                      L: if test_condition is false
                              then GOTO DONE
                            {body of the loop}
                            GOTO L
                      D: (next statement)

My question is, is this the way it is done in a "conventional" C
compiler ? Shouldn't it be in the lines of the previous version ?
Something like

                      L: if test_condition is false
                              then GOTO D
                            {body of the loop}
                            GOTO L
                      D: (next statement)

The article says that

In order to learn C properly, in other words, you must
learn this ( ie the way he said it would translate and not the
                    "regular" way )about machine languages.

I could not understand this either. I will be very grateful if any of
the knowledgeable netters can clarify this for me too.

As this argument purports to use the way in which the language
is compiled, I am asking this question in the comp.compilers
group. Further, please excuse me if it a really trivial point
that escaped my comprehension.

Thanks for the help in advance.


S. Bharadwaj Yadavalli, Dept. of Computer Science,
e-mail: University of Saskatchewan,
Ph: (306)-966-4907(O) Saskatoon, S7N 0W0 (Canada)
[It looks like a typo to me. In any event, the whole letter is written with
the author's tongue firmly in cheek. -John]

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.