Strange Variable Issue ...


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Dec 2012
    Location
    Türkiye
    Posts
    103


    Did you find this post helpful? Yes | No

    Default Re: Strange Variable Issue ...

    I think the problem is using array variables ... By creating proper byte variables everything works as I expect ...
    - Ipsa scientia potestas est -

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,645


    Did you find this post helpful? Yes | No

    Default Re: Strange Variable Issue ...

    if ByteCnt=2 how many times will it run through this for/next loop ?



    FOR GP=0 to ByteCnt ' Clear array bytes 0 to ByteCnt
    BytesIn[GP]=0
    NEXT



    when you set BytesIn[2] to 0 what var do you think will get clobbered


    its not a Strange Variable Issue ... its a write to an out of bounds array index

  3. #3
    Join Date
    Dec 2012
    Location
    Türkiye
    Posts
    103


    Did you find this post helpful? Yes | No

    Default Re: Strange Variable Issue ...

    Quote Originally Posted by richard View Post
    if ByteCnt=2 how many times will it run through this for/next loop ?



    FOR GP=0 to ByteCnt ' Clear array bytes 0 to ByteCnt
    BytesIn[GP]=0
    NEXT



    when you set BytesIn[2] to 0 what var do you think will get clobbered


    its not a Strange Variable Issue ... its a write to an out of bounds array index
    Hmm I've changed the line as follows

    FOR GP=0 to ByteCnt-1 ' Clear array bytes 0 to ByteCnt
    BytesIn[GP]=0
    NEXT
    And it works as expected ... Thank you for your answer Richard ..

    Now can you explain what happens when it tries to clear a nonexisting variable ? It clobbers my DAT variable next as it should not , yet somehow it does .. ?

    I think there is something happening on the background that is out of my knowledge ..
    - Ipsa scientia potestas est -

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,645


    Did you find this post helpful? Yes | No

    Default Re: Strange Variable Issue ...

    from the manual
    A single Array Variable can be visualized as a list of values. The variable name is
    how you access the list, and a number –or index– is used to point to any single
    value within the list.
    The index value is enclosed in brackets and appended after the array variable's
    name.
    myarray[index] = 0
    The index can be a literal number, a variable, or an expression.
    For the following examples, an array named "stored" is used:
    stored VAR WORD[8] 'Create an array named "stored"
    with 8 elements.
    Note that the 8 elements in our array are numbered 0 through 7. There is no
    element-8. This is very important, because PBP doesn't place a limit at the end of
    the array. If you write "stored[8]", PBP won't generate an error and you will be
    accessing memory outside of the array. (The end of the array is stored[7] and there
    is no stored[8].) This could have disastrous results and be very difficult to debug.
    The elements of "stored" can be written individually:
    stored[0] = 1260
    stored[1] = 2500
    Or, you might want to write values with a loop. You could read PORTB once per
    second and save 8 readings:
    FOR index = 0 TO 7 'Loop 8 times
    stored[index] = PORTB 'Save value of PORTB
    PAUSE 1000 'Wait a second
    NEXT index 'Loop again


    this is not just a pbp issue most 8 bit micro languages have the same limitation on array bounds checking ie . none at all

  5. #5
    Join Date
    Dec 2012
    Location
    Türkiye
    Posts
    103


    Did you find this post helpful? Yes | No

    Default Re: Strange Variable Issue ...

    Thank you Richard , for the amazing explanations ... Good to know and keep such knowledges for the pic that is working on the background of my brain ..
    - Ipsa scientia potestas est -

Similar Threads

  1. IF-THEN issue
    By jmgelba in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th February 2014, 22:09
  2. Assigning a string variable to another string variable
    By Christopher4187 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd June 2013, 17:55
  3. strange readings
    By cheezy1963 in forum General
    Replies: 6
    Last Post: - 29th November 2007, 00:46
  4. Code Issue - select case or 'if' issue - not sure why
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 7th October 2007, 08:52
  5. One variable made up of another variable
    By DynamoBen in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 1st September 2007, 00:18

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts