06/18/94: RE: C programming again Re: Msg 87911 by Delphi, | Category: Delphi - Programmers Den | 9 comments - (Comments are closed)

RE: C programming again Re: Msg 87911

88026 18-JUN 05:17 Programmers Den
RE: C programming again (Re: Msg 87911)
From: ALWAGNER To: COLORSYSTEMS

Please, bear with me as now I am confused on something I thought I understood!
I thought if you used the preincrementation the equivelent would be:
exp1;
while(exp2)
{
exp3;
statement;
}
Where as if post incrementation were used:
exp1;
while(exp2)
{
statement;
exp3;
}
In both cases, the exp3 is executed BEFORE the conditional is evaluated the
SECOND time, but where it is evaluated in relation to statement is what is
important here. If I am wrong, then why is the guy’s original program crashing?

The actual numbers he used to index his array were ok, but I maintain that
because he used preincrementation, the index actually went one past the
conditional on the last pass.

9 comments to RE: C programming again Re: Msg 87911

  • pucc_unknown

    88027 18-JUN 10:54 Programmers Den
    RE: C programming again (Re: Msg 88026)
    From: COLORSYSTEMS To: ALWAGNER (NR)

    The compiler doesn’t even notice whether or not use used preincrementation
    or postincrementation on the exp3 expression in a for() loop in assembling
    the control code for a for() loop. It has no bearing whatsoever on the
    structure of the loop. Regardless of which form the exp3 expression is,
    it is ALWAYS performed LAST, after any statement(s) the for() loop executes
    and just before the implied while() is branched back to.

    If you go back and re-read the original question, the program was NOT
    bombing out in every situation. He said it worked perfectly but only for
    small values for the array bounds. He only ran into a problem when he
    tried to make the arrays large, apparently too large for the stack space
    allocted for the program.

    ————————————
    Zack C Sessions

    They say, “Money talks”. But all mine ever says is, “Goodbye”.

  • pucc_unknown

    88042 18-JUN 16:44 Programmers Den
    RE: C programming again (Re: Msg 88026)
    From: JEJONES To: ALWAGNER

    Aha! Now I see the source of the confusion!

    The “pre” and “post” have to do with when the incrementing is done
    relative to grabbing the value of the variable as the result of the
    expression, not when it’s done relative to other statements.

    i = j++;

    assigns i the value of j and then increments j, while

    i = ++j;

    increments j and then assigns i the (changed!) value of j. In either
    case, the incrementing has to be done before the processor starts to
    execute the next statement, and it isn’t done until the processor has
    finished executing any previous statements. (In the case of a statement
    a little more convoluted than the above examples, there can be “places
    by which everything has to have been done” within a single statement,
    or as ANSI calls them, “sequence points”: function calls, comma
    expressions, && and ||, and ?:. But the principle’s the same.)

    Opinions herein are solely those of their respective authors.

    Clipper Chip: Big Brother Inside

  • pucc_unknown

    88188 24-JUN 21:19 Programmers Den
    RE: C programming again (Re: Msg 88042)
    From: JEVESTAL To: JEJONES

    > Aha! Now I see the source of the confusion!
    >
    > The “pre” and “post” have to do with when the incrementing is done
    > relative to grabbing the value of the variable as the result of the
    > expression, not when it’s done relative to other statements.
    >
    > i = j++;
    >
    > assigns i the value of j and then increments j, while
    >
    > i = ++j;
    >
    > increments j and then assigns i the (changed!) value of j.

    Thanks for explaining this, too avoid such confusions I just
    use the old standby j=j+1 when I want to increment j.

    Jim

    ======================== InfoXpress 01.01.00 OS-9/6809 ======================
    | Narnia BBS: 11pm-7am PDT serving CoCo OS-9 users
    —-|—- StG network: sysop@Narnia “Exclusively OS-9”
    | Delphi: JEVestal [at] delphi [dot] com
    Marysville, CA InterNet: JEVestal [at] narnia [dot] wa [dot] com
    | or : JEVestal [at] citrus [dot] sac [dot] ca [dot] us
    (916) 743-2617 Voice: 7am-11pm PDT :1 Corinthians 1:18 & Romans 1:16
    =============================================================================
    Jim Vestal: Assistant editor of The International OS-9 Underground,
    “Magazine dedicated to OS-9/OSK Users Everywhere