PDA

View Full Version : Question about Constants / Variables in Spin



CassLan
12-12-2009, 04:29 AM
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 (http://www.gothampropclub.com)

Prop Forum Search (Via Google) (http://search.parallax.com/search?site=parallax&client=parallax&output=xml_no_dtd&proxystylesheet=parallax&proxycustom=<HOME/>&ie=&oe=&lr=)


Oldbitcollector (Jeff)
12-12-2009, 04:34 AM
I don't have my prop hooked up, but it doesn't compile...

OBC

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

Visit the: The Propeller Pages (http://www.warrantyvoid.us/tiki-index.php?page=Propeller) @ Warranty Void.

jazzed
12-12-2009, 04:44 AM
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 :)

Luis Digital
12-12-2009, 04:54 AM
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.

potatohead
12-12-2009, 04:56 AM
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! (http://propeller.wikispaces.com/)
Chat in real time with other Propellerheads on IRC #propeller @ freenode.net (http://propeller.wikispaces.com/Join+us+on+IRC%21/)
Safety Tip: Life is as good as YOU think it is!

CassLan
12-12-2009, 05:17 AM
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 (http://www.gothampropclub.com)

Prop Forum Search (Via Google) (http://search.parallax.com/search?site=parallax&client=parallax&output=xml_no_dtd&proxystylesheet=parallax&proxycustom=<HOME/>&ie=&oe=&lr=)