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

  • pucc_unknown

    88040 18-JUN 16:13 Programmers Den
    RE: C programming again (Re: Msg 88027)
    From: JRUPPEL To: COLORSYSTEMS

    Can you tell me if there is a way to use the RMA in the Program deveoper’s
    Pak to compile C programs? Someone told me once that there was, but I lost
    the message and never really gave t
    it a try.
    Thanks,
    John Ruppel

  • pucc_unknown

    88059 19-JUN 07:28 Programmers Den
    RE: C programming again (Re: Msg 88027)
    From: ALWAGNER To: COLORSYSTEMS

    I must appologize to all for any confusion I may have been responsible for
    causing. Thank you Zack for setting me straight. As I had said I “thought”
    I understood for(;;) and ++x vs. x++. One of these days I gottsa learn ta
    stop eating shoe leather. Again my appologies and thanks.

  • pucc_unknown

    88043 18-JUN 17:44 Programmers Den
    RE: C programming again (Re: Msg 88040)
    From: COLORSYSTEMS To: JRUPPEL

    > Can you tell me if there is a way to use the RMA in the Program
    > deveoper’s Pak to compile C programs? Someone told me once that there was,
    > but I lost the message and never really gave it a try.

    Go to the libs, the Programmer’s Den I think, and download Rick Adams
    cc program. It is configurable to use rma and rlink instead of c.asm and
    c.link.

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

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

  • pucc_unknown

    88047 18-JUN 19:43 Programmers Den
    RE: C programming again (Re: Msg 88040)
    From: DBREEDING To: JRUPPEL

    > Can you tell me if there is a way to use the RMA in the Program
    > deveoper’s Pak to compile C programs? Someone told me once that there was,
    > but I lost the message and never really gave t
    > it a try.

    There are several ways:

    1) rename rma in your cmds directory c.asm. You’ll also need to use the
    new linker for these files, old linker won’t work. Rename rlink c.link.

    2) use a file editor, “ded” is good, and edit “cc1″ to look for new names.
    find the sequence “c.asm”, followed by ’0′, change to “rma”, next char=0.
    change “c.link”+0 to “rlink”+0. Don’t have to fool with anyth that would
    follow.

    3) Get a replacement for “cc1″. There are several, many are in source form
    where you can compile new “cc” yourself, some already look for new
    versions of asm/linker.

    Just be sure that you use new linker to link “rma” output. The new linker
    CAN link ROF’s compiled by old assembler, though.

    — David Breeding –
    CompuServe : 72330,2051
    Delphi : DBREEDING

    *** Sent via CoCo-InfoXpress V1.01 ***
    ^^^^ ^^^^^^^^^^

  • pucc_unknown

    88193 24-JUN 23:16 Programmers Den
    RE: C programming again (Re: Msg 88188)
    From: COLORSYSTEMS To: JEVESTAL

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

    I use ++i syntax all the time. Not fer sure, but I think it actually
    generates more efficient asm than i = i + 1. And I never, ever mix up
    incrementation in an expression like:

    i = j++;

    For the most part, this is safe, but something like:

    i = j++ >> 8;

    may or may not work like you think it should. All compilers are not
    created equal!!! :-)

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

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

  • pucc_unknown

    88210 25-JUN 23:25 Programmers Den
    RE: C programming again (Re: Msg 88193)
    From: PAGAN To: COLORSYSTEMS

    >I use ++i syntax all the time. Not fer sure, but I think it actually
    >generates more efficient asm than i = i + 1.

    If you’re using the 3.2 compiler then the two expressions do result in
    different assembler. The “cntr = cntr+1″ generates an extra move operation.

    Using a register variable for the counter in the loop:

    3.2: cc -xiat=/r0

    for(cntr=0;cntr<100;cntr++)

    moveq.l #0,d4
    bra _7
    _5
    addq.l #1,d4
    _7
    moveq.l #100,d0
    cmp.l d4,d0
    bgt _5

    for(cntr=0;cntr<100;cntr=cntr+1)

    moveq.l #0,d4
    bra _7
    move.l d4,d0
    _5
    addq.l #1,d0
    move.l d0,d4
    _7
    moveq.l #100,d0
    cmp.l d4,d0
    bgt _5

    Ultra C, OTOH, generates the same code for both cases:

    Ultra C: cc -ebe -td=/r0

    _$L0
    moveq.l #0×0,%d0
    _$l321
    addq.l #1,%d0
    moveq.l #0×64,%d1
    cmp.l %d1,%d0
    blt _$l321

    Note that I cleaned the above code up a bit for publication .

    Stephen (PAGAN)

    Men are apt to mistake the strength of their feeling for the strength of
    their argument. The heated mind resents the chill touch and relentless
    scrutinity of logic. – William Gladstone