Action! Programming for the Atari 8-bit Computer - Part 18 - Introduction to Pointers

แชร์
ฝัง
  • เผยแพร่เมื่อ 18 ก.ย. 2024
  • The 18th in a series of videos in programming in Action! for the Atari 8-bit computers.
    In another response to a viewer comment, this is a short video on using Pointer variables in Action! and when you would and would not want to use them. Thanks to rscott hayes for the inspiration.
    Code for my videos are at my GitHub at GitHub.com/Davi...

ความคิดเห็น • 3

  • @DaveS_WI
    @DaveS_WI 2 ปีที่แล้ว +1

    Great topic! IMHO, Action lets you make variables that are ambiguous as to them bring a pointer or not (and can cause coding errors). The subtle difference of x=$1234 vs. x=[$1234] - makes it unfortunately very easy to confuse a pointer with a regular variable. For myself, if I treat the variable as a pointer, I like to call it a POINTER type.

  • @mmille10
    @mmille10 2 ปีที่แล้ว +1

    In my mind, just to clarify what you said about "scrloc^=chrbyte", this is dereferencing scrloc. It's the equivalent of if you were to say in C,
    char chrbyte, *scrloc;
    ...
    scrloc = savmsc + len - 1;
    chrbyte = Gr2IntChr(text[len]);
    *scrloc = chrbyte;
    Re. how this is the equivalent of a poke
    I was doing the same thing when I did C programming on the Atari 8-bit. Though, I usually didn't use explicit pointers, like you're using here. A lot of what I did with it was seeing if I could convert all of my Data Structures assignments from the CS course I took to work on the Atari. I got all of them to work. Though, I had to come up with my own heap management routines. In that case, I used an explicit pointer (assigning a physical address to it) as the base address for my heap. I seem to remember the C library I was using had poke() and peek() functions, but I never used them, because just dereferencing a pointer was easier to express, and did exactly the same thing.
    Though, I think having poke() and peek() around can be convenient for incidental value assignments, and reads, to/from addresses. If you want to just set a value that the Atari's OS or hardware will pick up, and you're not going to use that address in the rest of your code, using poke() is easier than assigning that address to a pointer (or a variable in Action), and then dereferencing it, to assign the value.

    • @davidarlington1206
      @davidarlington1206  2 ปีที่แล้ว

      Yep, you've got it.
      "If you want to just set a value that the Atari's OS or hardware will pick up, and you're not going to use that address in the rest of your code, using poke() is easier than assigning that address to a pointer (or a variable in Action), and then dereferencing it, to assign the value."
      I still prefer to assign the address to a var and using the var name for readability sake, rather than Poke() some numeric constant. I like all constants up top in one place.