Shop OBEX P1 Docs P2 Docs Learn Events
passing characters to methods ? — Parallax Forums

passing characters to methods ?

Don PomplunDon Pomplun Posts: 116
edited 2007-03-12 15:05 in Propeller 1
Parameters passed to methods are all longs. I asume if I call a method and supply a parameter as "A", it will be seen at the other end as $00000041.
If I supply the parameter as "AB" will it come in as $00004142 ?
(Obviously if this works, my parameter strings are limited to 4 characters)

If this is taboo, is there a way ? Is it passing pointers to the strings?

TIA,
-- Don

Comments

  • Martin HebelMartin Hebel Posts: 1,239
    edited 2007-03-12 05:54
    Strings (and arrays) may be used by passing a pointer - @
    A routine may accept a pointer

    ···
    PUB test(stringptr) | x
      'code to do something with string
      x := strsize(stringptr)
    
      etc
    

    The calling function sends the address of the string
    test(string("hello World!"))
    or
    VAR
      Byte myStr[noparse][[/noparse]20]
    
     
    Pub Main
      test(@myStr)
     
    

    Hard to come up with simple examples, hope this was clear enough.
    -Martin


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    StampPlot - GUI and Plotting, and XBee Wireless Adapters
    Southern Illinois University Carbondale, Electronic Systems Technologies
  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-12 06:00
    All parameters are longs, therefore you are limited to passing at most 4 characters as a parameter. As you suspect, you can pass the address of a character string. You can define a constant string in a DAT section and pass the address of it. If the label on the string (or any constant) is "foo", you can pass the address by using the "@" operator as in "@foo". To make this easier, there is a pseudo-function ("string") that allows you to specify a list of string literals and byte values. It generates a constant, sticks a zero byte at the end and provides the address of the first byte. For example, if you use the tv_text video driver, declared as "dsp", you can write: dsp.str(string("This is a string.",13)). You may still want to declare these messages in a DAT section if the same message is used repeatedly since duplicates are not combined.
  • Don PomplunDon Pomplun Posts: 116
    edited 2007-03-12 15:05
    Those get me on the right track.
    My House Control system is now off the PC and on the Prop (though I haven't seen any radical drop in the electric bill yet).
    Thanks.
    -- Don
Sign In or Register to comment.