Author Topic: static vars  (Read 9045 times)

0 Members and 1 Guest are viewing this topic.

Offline bored_student

  • LV3 Member (Next: 100)
  • ***
  • Posts: 44
  • Rating: +3/-0
    • View Profile
static vars
« on: October 31, 2012, 12:22:17 pm »
I wanted to make my program code more clear.
So I decided to use static vars that replace some L1+... commands:
example:
Code: [Select]
L1+12 -> GDB0XVAL
L1+14 -> GDB0YVAL
...
X -> {GDB0XVAL}R
Y -> {GDB0YVAL}R

Is this slower than this:
Code: [Select]
X -> {L1+12}R
Y -> {L1+14}R
or is it the same after compiling
« Last Edit: October 31, 2012, 12:22:49 pm by bored_student »
Sorry for my bad English, I'm German.

Offline Eeems

  • Mr. Dictator
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6268
  • Rating: +318/-36
  • little oof
    • View Profile
    • Eeems
Re: static vars
« Reply #1 on: October 31, 2012, 12:29:58 pm »
If it is a static var then I would assume that it would be the same speed. Static variables should be replaced by the actual value on compile if it's anything like static variables in other languages.
/e

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: static vars
« Reply #2 on: October 31, 2012, 12:49:52 pm »
If you want to make it even clearer, you can do that:

L1+12→°XVAL
L1+14→°YVAL
...
X→XVAL
Y→YVAL

What you did there is declare two new custom variables, XVAL and YVAL, whose bytes are located at L1+12 and L1+14 ;)

edit
note that the ° is the degree symbol in Angle (2nd Apps).
« Last Edit: October 31, 2012, 12:50:42 pm by Hayleia »
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline bored_student

  • LV3 Member (Next: 100)
  • ***
  • Posts: 44
  • Rating: +3/-0
    • View Profile
Re: static vars
« Reply #3 on: October 31, 2012, 01:03:40 pm »
thank you a lot  ;D

I have never read that you can do something like that   O.O
So I can easily make new vars.
How many characters can I use to name them and
from where do you know such things?
Sorry for my bad English, I'm German.

Offline Eeems

  • Mr. Dictator
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6268
  • Rating: +318/-36
  • little oof
    • View Profile
    • Eeems
Re: static vars
« Reply #4 on: October 31, 2012, 01:24:25 pm »
You might find reading the documents here useful: http://axe.eeems.ca/
/e

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: static vars
« Reply #5 on: October 31, 2012, 02:39:43 pm »
How many characters can I use to name them and
from where do you know such things?
You can have up to 5 characters. I think the first one has to be an uppercase letter but maybe I am wrong.
And I know this kind of things by asking questions on this awesome website that is Omnimaga ;)
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline bored_student

  • LV3 Member (Next: 100)
  • ***
  • Posts: 44
  • Rating: +3/-0
    • View Profile
Re: static vars
« Reply #6 on: November 01, 2012, 02:53:44 pm »
You might find reading the documents here useful: http://axe.eeems.ca/
This are the files included in the Axe download but I cant find something like
const -> °Var 

however now I know it
thank you both you have helped me a lot :)
Sorry for my bad English, I'm German.

Offline shmibs

  • しらす丼
  • Administrator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2132
  • Rating: +281/-3
  • try to be ok, ok?
    • View Profile
    • shmibbles.me
Re: static vars
« Reply #7 on: November 01, 2012, 06:31:35 pm »
if you are storing the value to a variable then i am fairly certain it will be slower. i think the axe compiler simplifies L1+whatever to a single, in-line constant value, while accessing the other will first store the value to a different position in RAM during execution and then have to recall that value from the position in RAM when it is calling the value later.

Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Re: static vars
« Reply #8 on: November 01, 2012, 08:48:49 pm »
The custom variable method was created to make creating custom variables relatively easily.
x->{L1+2}r is the same speed and size as L1+2->oVAR : x->VAR

Note that you can abuse the custom variable system to create named constants, similar to finals in java, only you can actually notice the speed difference. For example, 32->oMapW allows you to use oMapW in place of 32, anywhere in your code. Useful for debugging and clarity :)
« Last Edit: November 01, 2012, 08:49:27 pm by squidgetx »