Shop OBEX P1 Docs P2 Docs Learn Events
Aliasing — Parallax Forums

Aliasing

NewzedNewzed Posts: 2,503
edited 2005-03-18 16:17 in BASIC Stamp
I have a variable - "sertext var byte(12)".

This variable is used once at the beginning of the program cycle, and changes each time the program cycles.

I have tried aliasing like this:

a· var· sertext(0)
b· var sertext(1)

but the program will not accept it.· Is there any way to alias the bytes in sertext - I need more variables but RAM is full.· I am using a BS2P24 at the present time.

Sid

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-03-18 14:02
    The compiler doesn't let you alias an indexed element of an array.· There is a way around it -- it just requires a bit of typing:

    Instead of...

    myText····· VAR···· Byte(3)

    Do this:

    myText······VAR···· Byte
    myText1··· ·VAR···· Byte
    myText2···· VAR···· Byte

    You can still treat "myText" as an array of three elements, and now the compiler will let you alias the individual entities:

    header···· ·VAR···· myText
    cmd········ VAR··· ·myText1
    dByte······ VAR···· myText2

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • NewzedNewzed Posts: 2,503
    edited 2005-03-18 15:01
    Thanks, Jon.· I'll give that a shot.· To save typing·can I write:

    a· var byte(12)

    a· var byte
    a1 var byte
    a2 var byte

    and so on.

    Sid
  • Tom WalkerTom Walker Posts: 509
    edited 2005-03-18 15:13
    Not quite.

    As Jon stated: "You can still treat "myText" as an array of three elements, " so the concept can be expressed as:

    myText VAR Byte
    myText1 VAR Byte
    myText2 VAR Byte

    and you can address

    myText(0) which will equal myText
    myText(1) which will equal myText1
    myText(2) which will equal myText2

    Or am I missing the boat, Jon?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Truly Understand the Fundamentals and the Path will be so much easier...
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-03-18 16:07
    You're on the boat, Tom. In actualy fact, PBASIC treats the variable RAM space as an implicit array which can come in handy if you know how to handle it. What is critical about defining arrays manually (so you can alias elements) is that you MUST define the elements in order.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • BeanBean Posts: 8,129
    edited 2005-03-18 16:17
    I think Sid is thinking of the SX/B aliasing. SX/B does allow what he had originally posted.
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out· the "SX-Video Display Module"

    www.sxvm.com

    "A problem well defined, is a problem·half solved."
    ·
Sign In or Register to comment.