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

Constants

Dr_AculaDr_Acula Posts: 5,484
edited 2010-09-20 21:48 in Propeller 1
Are constants declared in the CON section of the Main program available to other spin programs that are called from Main?

I was expecting they would be, but when I move the constants from the local spin program (eg the vga driver) to the main spin program, I get an "Unresolved symbol" error.

This is on BST. Am I missing something obvious here? Any help would be most appreciated.

Comments

  • TinkersALotTinkersALot Posts: 535
    edited 2010-09-20 19:20
    I think thy are referenced like this:

    ObjName#ConstantName

    Where ObjName is the "local name" for the object in the IMPORTING file.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-09-20 19:20
    Nope, unfortunately not. You can access constants from objects that you declare, but it does not work in the other direction.

    Oh, just noticed the BST reference. Dunno know about that. I was referring to the Prop IDE.

    -Phil
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2010-09-20 19:23
    @tinkersalot - I'll look into that one
    @Phipi - It probably doesn't matter whether I reference from the main to a sub object or the other way. All I really want to do is to be able to declare something once. So even it it isn't where I expect it to be (even buried in code) I can put comments in other places saying where it is. I hope that makes sense!
  • TinkersALotTinkersALot Posts: 535
    edited 2010-09-20 19:25
    I recently started to put ALL constants into a single "header file" that just has contants defined in it. Then all files that reference these constants can import these constants by just creating a local object to bring in this "header file".

    The only thing I had to do was to put a "throw away method" in the "header file" just to keep the propeller tool "happy."

    Maybe that helps

    For example see the use of the PinDefs file/objects in my program here:
    http://forums.parallax.com/showthread.php?t=125583
  • Mike GreenMike Green Posts: 23,101
    edited 2010-09-20 20:36
    I've done the same sort of thing that TinkersALot described. It works well for me. Also look at BoeBotBasic for another example (BB_Definitions.spin).
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2010-09-20 21:01
    Thanks for the suggestions. As another possible solution, I might see whether Brad would mind adding another # directive eg #localconstant = myconstant
  • Heater.Heater. Posts: 21,230
    edited 2010-09-20 21:48
    Dr. A,
    I might venture to suggest that if you have started to long for features such as "#define something somevalue" then is time to move up to using C instead of spin.

    If BradC were to add all the "little" extentions to Spin that people request then it would resemble C more and more.

    Having people produce more amd more objects in "BradC Spin" would be something of a disaster for code sharing as we are used to in the Prop world. Having forked the language and fractutured the user base.

    I have been using Free Pascal at work recently and noticed tht this as happened to Pascal a long time ago. It has had so many of these little tweaks added that you may as well use C.
Sign In or Register to comment.