Hacker News new | past | comments | ask | show | jobs | submit login

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.



I'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.


You 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.


QBasic 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).


Real 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.


Next you'll be telling me laser pointers have colours and there are several dog breeds named 'pointer'. Pointer dogs are furry.


I 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.


The 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.


So 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_Own...

Or to stay with QuickBasic dialects, Freebasic music tunes

https://www.freebasic.net/wiki/wikka.php?wakka=TblComparison...

Which also provides the SIZEOF chord, simplifying the increment operations of memory addresses.


> For one thing, they're typed.

Pointers were invented in PL/I, where they were specifically untyped.


The comment I replied to makes a specific comparison with C not PL/I.


Well, 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.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: