Shop OBEX P1 Docs P2 Docs Learn Events
couldnt find the bug , interessant — Parallax Forums

couldnt find the bug , interessant

davrandavran Posts: 12
edited 2008-04-16 23:27 in Propeller 1
i wanted to make a simple frequency generator. but at the first draft my software failed..

the code below fails between the lines 30-34. the loop causes the screen lost and pin0 gives a variable frequency.

does the code have any error or am i doing sth wrong?

thanks for the answers.

here is the full source :

Post Edited (davran elektronik) : 4/16/2008 8:23:07 PM GMT
327 x 521 - 7K
168 x 80 - 916B

Comments

  • davrandavran Posts: 12
    edited 2008-04-16 20:45
    i deleted the byte variable d after that the code worked. now i must find sth else instead of d .

    but what is wrong with "d"


    kuku2fz4.png

    kuku3oc4.png

    kuku4at3.png

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "Give a lie twenty-four hours start, and it will take a hundred years to overtake it.
    " (C.F. Dixon-Johnson, British author of the 1916 book, "The Armenians," appalled over the deceitful practices of his book's subject.)

    www.tallarmeniantale.com/

    Post Edited (davran) : 4/16/2008 8:59:01 PM GMT
    168 x 80 - 916B
    160 x 85 - 995B
    166 x 72 - 845B
  • Mike GreenMike Green Posts: 23,101
    edited 2008-04-16 21:33
    Your problem is that array subscripts run from 0 to n-1 where the array is declared to be of size n.

    Your loop assumes that the subscripts run from 1 to n, so the byte after p gets altered when you reference p[noparse][[/noparse] 10 ].
  • StefanL38StefanL38 Posts: 2,292
    edited 2008-04-16 21:46
    hello davran,

    in your first version the loop starts with repeat (d-1) with d= 1 it means repeat 0
    and this might be endlessly doing p[noparse][[/noparse]c] *= 10

    what the hell should the second version do with repeat (d-1-d+2) ?????

    third version starts with repeat 1

    best regards

    Stefan
  • rokickirokicki Posts: 1,000
    edited 2008-04-16 23:27
    Just to make a minor correction:

    in C,

    int a[noparse][[/noparse]10]

    declares space for *10* elements, indexed 0..9.

    I couldn't let the "11 elements" comment confuse anyone and lead to more buffer overruns or whatnot.
Sign In or Register to comment.