Shop OBEX P1 Docs P2 Docs Learn Events
Memory over lap problem — Parallax Forums

Memory over lap problem

KC8DKTKC8DKT Posts: 76
edited 2007-02-28 11:26 in Propeller 1
Byte FanRPM[noparse][[/noparse]2], A

· FanRPM[noparse][[/noparse]0] := 1
· FanRPM[noparse][[/noparse]1] := 1
· FanRPM[noparse][[/noparse]2] := 1

Y does the above·spill over into byte 3 "Var A".· I have 8 temp probes that use

repeat·IDX from 0 to 7
· Temp[noparse][[/noparse]IDX] := "Some ADC math"

that is doing the same thing.

There must be some little dumb thing I am missing because I found the attached chart in the Prop manual that skips from Long[noparse][[/noparse]0] to Long[noparse][[/noparse]2] as well.·· Anyone have a·SIMPLE answer for this?· Be gentle,· still new to the Prop,·Spin, and english...tongue.gif

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-27 20:12
    You've declared FanRPM as a 2 byte array, yet are referencing FanRPM[noparse][[/noparse] 2]. This will "spill over" into the next variable (A in this case). You have to declare the array (whether FanRPM or Temp) to be large enough for the largest subscript you will use. Keep in mind that subscripts start at zero, so the array size has to include that (if the largest subscript used is 2, then declare the array as having 3 elements).
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-02-27 20:33
    This is commonly refered to as "the off by one error". In languages where the first element uses the index 0 (Spin is one of them), the array is declared with N elements which are adressed as 0,1,2,..,N-2,N-1. The Nth element's index is N-1.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • KC8DKTKC8DKT Posts: 76
    edited 2007-02-27 20:35
    Thanks, thought the arrays started at 0. What is the deal with the Long[noparse][[/noparse]0] skip Long[noparse][[/noparse]1] then Long[noparse][[/noparse]2] in the chart thats in the manual?

    Post Edited (KC8DKT) : 2/27/2007 8:41:29 PM GMT

  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-27 21:00
    Aha! The infamous "typographical error" problem. When something doesn't really make sense, you may be right! You might send an e-mail to Stephanie Lindsay at Parallax about this so it can be corrected in the next edition of the manual.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-02-27 21:01
    That is a typo, thanks for catching it. We will put that in the errata shortly.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • KC8DKTKC8DKT Posts: 76
    edited 2007-02-28 04:20
    Thank god, thought I was just missing some thing again...
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2007-02-28 09:26
    If you are placing memory over your lap you really do have a problem [noparse]:)[/noparse]

    Thank you, you've been a wonderful audience

    Graham
  • JamesxJamesx Posts: 132
    edited 2007-02-28 11:26
    Graham:

    Finally got the joke, after reading it 5 times smile.gif

    Jim C
Sign In or Register to comment.