-Y : Dynamic link for string literals

Beta Testing discussion on mikroBasic PRO for AVR.
Post Reply
Author
Message
stevech
Posts: 38
Joined: 20 Aug 2007 16:47

-Y : Dynamic link for string literals

#1 Post by stevech » 12 Dec 2008 21:04

Please explain this command line switch

-Y : Dynamic link for string literals.

User avatar
zristic
mikroElektronika team
Posts: 6608
Joined: 03 Aug 2004 12:59
Contact:

Re: -Y : Dynamic link for string literals

#2 Post by zristic » 16 Dec 2008 13:54

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.

stevech
Posts: 38
Joined: 20 Aug 2007 16:47

#3 Post by stevech » 24 Dec 2008 06:45

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.

User avatar
zristic
mikroElektronika team
Posts: 6608
Joined: 03 Aug 2004 12:59
Contact:

#4 Post by zristic » 25 Dec 2008 13:37

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.

Post Reply

Return to “mikroBasic PRO for AVR Beta Testing”