4 ms·
That's an approach to directly accessing memory not an approach to 'pointers'. Pointers are an entirely different language facility. For one thing, they're type
by pvg 8y ago
That's an approach to directly accessing memory not an approach to 'pointers'. Pointers are an entirely different language facility. For one thing, they're typed. PEEK just gives you bytes and you can neither reference or dereference anything.
- chrisseaton 8y ago> For one thing, they're typed. Pointers were invented in PL/I, where they were specifically untyped.
- pvg 8y agoThe comment I replied to makes a specific comparison with C not PL/I.
- batteryhorse 8y agoI'm not sure I understand. Can't you do something like PEEK(PEEK(a)) or PEEK(PEEK(a)*256+PEEK(a+1)) ? I always thought of pointers as indirect addressing mode when I was learning about the 6502.
- pvg 8y agoYou can't take the address of a A$, for instance, and do anything with it. And in your case 'A' is always in bytes unlike a C pointer which has arithmetic that depends on its type. PEEKs and POKEs are not pointers.
- pjmlp 8y agoReal pointers, those used by Assembly are also untyped. Other Basic dialects, including QBasic's big brother, had a Varadr function or similar, to take an address. C is not the absolute truth in pointer manipulation across programming languages.
- pvg 8y agoNext you'll be telling me laser pointers have colours and there are several dog breeds named 'pointer'. Pointer dogs are furry.
- pjmlp 8y agoI don't need jokes about laser pointers to present languages, some of them much older than C, which have pointers with 1:1 features to C ones. Of course, it kind of hurts the urban myth that C is a special snowflake among systems programming languages, having languages almost 10 years older with such features.
- pvg 8y agoThe original comment was a comparison of pointers in C and PEEKs and POKEs in BASIC. So making up stuff about how assembly has 'pointers' or trying to start some argument about C with a statement nobody made is not really much more directly related to what we're discussing than a comment about the music of the Pointer Sisters.
- pjmlp 8y agoSo back to Basic then, this is Turbo Basic (1987) ' a = *addr a = PEEK (addr%) ' *addr = value POKE addr%, value 'a = addr a = addr 'addr++ INCR addr%, 2 'a = &variable DEF SEG = VARSEG(variable) a = VARPTR(varible) a = VARPTR$(varible) Album, http://www.bitsavers.org/pdf/borland/Borland_Turbo_BASIC_Owners_Handbook_1987.pdf http://www.bitsavers.org/pdf/borland/Borland_Turbo_BASIC_Own... Or to stay with QuickBasic dialects, Freebasic music tunes https://www.freebasic.net/wiki/wikka.php?wakka=TblComparisonC https://www.freebasic.net/wiki/wikka.php?wakka=TblComparison... Which also provides the SIZEOF chord, simplifying the increment operations of memory addresses.
- badsectoracula 8y agoQBasic has VARADR (or VARADDR) that gives you the memory location for a variable. QuickBasic also has SADD which gives you the memory location for the first character of a string, although for some reason it isn't available in QBasic (but you can figure out from the string data anyway, VARADR(A$) points to a pair of length+data words).
- meuk 8y agoWell, I'm not sure if there are strict rules to what should be called a pointer and what not (which was why I was a little bit vague in my post: In my defense, I stated "there are no pointers"). I think you can still dereference something by just manually copying the bytes.