Shop OBEX P1 Docs P2 Docs Learn Events
Question about Constants / Variables in Spin — Parallax Forums

Question about Constants / Variables in Spin

CassLanCassLan Posts: 586
edited 2009-12-11 22:17 in Propeller 1
Hi all,

If I define a constant as the sum of two variables:
CON
     VARSUM = VAROne + VARTwo
 
VAR
 
     Byte VAROne, VARTwo

As I change the values of VAROne and VARTwo, will the value of VARSUM change automatically?
Or would I have to make VARSUM a variable and update its value as VAROne and VARTwo change?

I would test this but am not near a setup right now, and am making some outlines for a program.

Thanks,

Rick

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


NYC Area Prop Club

Prop Forum Search (Via Google)

·

Comments

  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2009-12-11 21:34
    I don't have my prop hooked up, but it doesn't compile...

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Visit the: The Propeller Pages @ Warranty Void.
    1152 x 864 - 104K
  • jazzedjazzed Posts: 11,803
    edited 2009-12-11 21:44
    CassLan said...
    As I change the values of VAROne and VARTwo, will the value of VARSUM change automatically?
    Or would I have to make VARSUM a variable and update its value as VAROne and VARTwo change?
    A constant can only change at compile time. Be thankful that the example does not compile [noparse]:)[/noparse]
  • Luis DigitalLuis Digital Posts: 371
    edited 2009-12-11 21:54
    The operations in the "CON" section are performed by the Propeller IDE (compile time) no Propeller Chip (run time).

    CON
    VARSUM = VAROne + VARTwo

    It is simply a reference, something easy to remember.
  • potatoheadpotatohead Posts: 10,261
    edited 2009-12-11 21:56
    Constants are computed at compile time.

    If you calculate something with a constant, then use that constant in your program, the value result of the calculation will be put into the program just as if you had typed it in.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Propeller Wiki: Share the coolness!
    Chat in real time with other Propellerheads on IRC #propeller @ freenode.net
    Safety Tip: Life is as good as YOU think it is!
  • CassLanCassLan Posts: 586
    edited 2009-12-11 22:17
    WOW, talk about fast responses!

    Ok, I see, at compile time it replaces chunks of my program with the appropriate values for the constants, its merely a human aid in writing the software.

    Thanks!

    Rick

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    NYC Area Prop Club

    Prop Forum Search (Via Google)

    ·
Sign In or Register to comment.