forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to use transfer

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
m.burkhardt



Joined: 02 Sep 2008
Posts: 26

PostPosted: Fri Jun 10, 2011 12:48 pm    Post subject: How to use transfer Reply with quote

Hello I hope this is my last question! Wink

Is there anyone who can explane the use of transfer in the following case:
Code:

    OBJECT("System.String") :: STR
    CHARACTER*6 :: CHR
!
    STR = "ABCDEF"
    CHR = transfer(STR, CHR)
!
    PRINT *,CHR

The output string are hieroglyphics. So I think, I never get the string 'ABCDF' but the Memory address of the variable (pointer).

I try the following with no changes:
Code:

    OBJECT("System.String") :: STR
    CHARACTER*6 :: CHR
    INTEGER*2 LENGTH
!
    LENGTH = 6
    STR = "ABCDEF"
    CHR = transfer(STR, CHR, LENGTH)
!
    PRINT *,CHR


The outoput is the same as on the top!

What do I wrong? Or how can I get access of the value (string) and not of the address (pointer)?

Greetings from Germany
Michael
Back to top
View user's profile Send private message Send e-mail MSN Messenger
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Sat Jun 11, 2011 7:38 am    Post subject: Reply with quote

Transfer just copies "bits" from one variable to another. The target and source variables need to be the same size and it needs to make sense to copy the bits. Think of it as a run-time form of EQUIVALENCE.

As the bit patterns for the string "ABCDEF" are probably different for the two variable types OBJECT("System.String") and CHARACTER*6 then transfer is not much use in this case. You will just get garbage.

However something like OBJECT("System.Int32") and INTEGER*4 are likely to have the same bit pattern representation.

Transfer isn't very portable. I use it to implement generic function interfaces in Fortran 95 (where transfer is made to "coerce" a variable into an integer array for passing, and later this is transfered back to the variable type). This is quite portable but it breaks some optimizing compilers. Once we get fully working Fortran 2003 compilers there are better ways to do this.
Back to top
View user's profile Send private message
Sebastian



Joined: 20 Feb 2008
Posts: 177

PostPosted: Mon Jun 13, 2011 11:29 am    Post subject: Reply with quote

.NET strings are unicode, though I don't know if this is the only problem here.
Back to top
View user's profile Send private message
m.burkhardt



Joined: 02 Sep 2008
Posts: 26

PostPosted: Wed Jun 15, 2011 6:15 pm    Post subject: Reply with quote

Thanks allot!

It Works!!!

Greetings from Germany
Michael
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group