Page 1 of 1

-Y : Dynamic link for string literals

Posted: 12 Dec 2008 21:04
by stevech
Please explain this command line switch

-Y : Dynamic link for string literals.

Re: -Y : Dynamic link for string literals

Posted: 16 Dec 2008 13:54
by zristic
Literal strings need to be placed in RAM when you are passing them by reference. This is illegal by Pascal standard, but we are allowing it for helping users with the code management.

Therefore, if you are passing a literal string to a function which accepts a var parameter, then we copy the literal to RAM and finally pass the RAM address to the called function.

If you use -Y then a literal string will be placed on a local frame of the current procedure (dynamic link).

If you do not use -Y then a literal string will be linked as global variable (static RAM).

I hope I explained it well, otherwise be free to reask.

Posted: 24 Dec 2008 06:45
by stevech
thanks, but not clear.
This topic is in mikroBasic, but the comment mentions Pascal.

Is there any way to pass a pointer to a const in flash to a function that expects that?

I would never want to pass a string or compound type that is in flash or RAM by value. Too big and slow.

The documentation for mikroBasic is silent as to what -Y means.

Posted: 25 Dec 2008 13:37
by zristic
stevech wrote:Is there any way to pass a pointer to a const in flash to a function that expects that?

Code: Select all

  program test

  const ArrayOfBytes as byte[4] = (1,2,3,4)

  sub procedure ExpectConstInFlash(dim const CinFlash as ^byte)
    PORTB = CinFlash^ ' = 1
    CinFlash = CinFlash + 1

    PORTB = CinFlash^ ' = 2
    CinFlash = CinFlash + 1

    PORTB = CinFlash^ ' = 3
    CinFlash = CinFlash + 1

    PORTB = CinFlash^ ' = 4
  end sub

  main:
   ...
    ExpectConstInFlash(@ArrayOfBytes) 
   ...
  end.

-Y has nothing to do with this. It deals with literal string constants when they are needed to be placed in RAM (there is a need for this if you pass a literal constant to a function which expects a parameter by reference). In this case the literal string will be copied to RAM. Then the starting RAM address will be passed to a function which expects a parameter by reference.

Now, which RAM space will be used for this purpose is defined by the switch -Y. This is explained in the earlier post.