Shop OBEX P1 Docs P2 Docs Learn Events
Numeric Variable Type Conversions — Parallax Forums

Numeric Variable Type Conversions

william chanwilliam chan Posts: 1,326
edited 2008-03-07 00:06 in Propeller 1
Hi,

I can't find any type-conversion (type-casting) commands in SPIN.

1. What happens when we assign a byte value to a long variable?
Will the value be preserved?

2. When we assign a word variable with a value in a long variable?

3. What happens if a procedure requires a byte parameter, but instead we supply it with a long?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.fd.com.my
www.mercedes.com.my

Comments

  • deSilvadeSilva Posts: 2,967
    edited 2008-03-06 23:11
    In SPIN there is hardly any "magic" - it's genarally the most simple you can imagine!

    (1) The sign will not be extended, there is a specific operator if you need that: ~
    (2) The sign will not be extended, there is a specific operator if you need that: ~~
    (3) This - again - is a nonsense question
  • jazzedjazzed Posts: 11,803
    edited 2008-03-06 23:18
    On 3: Parameters to methods are like void* parameters in C.
    You can cast with byte, word, and long. You get lots of "flexibility" here; don't hurt yourself.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    jazzed·... about·living in·http://en.wikipedia.org/wiki/Silicon_Valley

    Traffic is slow at times, but Parallax orders·always get here fast 8)
  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-06 23:50
    On 3: All parameters and local variables are implicitly declared as longs. If you pass a byte value, ordinary assignment rules will apply ... the byte value will be zero extended to make a long value.
  • jazzedjazzed Posts: 11,803
    edited 2008-03-07 00:06
    Mmm. Yea, C does tend to sign extend whatever is in the MSB unless you cast it "correctly" [noparse]:)[/noparse] C void* generally follows the natural width of the architecture unless overriden as is possible in mips64 for example. But ... you have to know C to understand that ... as most of us do.· ADDED: Fair clarification of course Mike.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    jazzed·... about·living in·http://en.wikipedia.org/wiki/Silicon_Valley

    Traffic is slow at times, but Parallax orders·always get here fast 8)

    Post Edited (jazzed) : 3/7/2008 12:11:32 AM GMT
Sign In or Register to comment.