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 

Calling Salford Fortran from C with value arguments and C string arguments

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
Anonymous
Guest





PostPosted: Wed Nov 02, 2005 2:19 am    Post subject: Calling Salford Fortran from C with value arguments and C st Reply with quote

I'm having some difficulty setting up my company's Salford Fortran interface from our product's C code.
The difficulty I'm having is defining Salford Fortran routines to be called from C with (i) value arguments and (ii) C string arguments.
The following code fragment is where I've got to so far (I'm having to wrap the calls to Salford Fortran from C and pass the address of the value arguments to the Fortran).
Also I'm not sure how to persuade Salford Fortran to receive a C string as a Fortran string (note that I can do this Compaq/Digital Fortran)?

Salford Fortan
--------------

F_STDCALL subroutine display(msg,len)
implicit none
integer :: len
??????? :: msg
write(*, *) msg
end

typedef void (__stdcall * Callback_displayf)(void *msg, void *len);

void __stdcall Callback_display(Callback_messagef f, const char *msg, int len)
{
/* I have a pointer to 'display' in 'f' from an earlier call from Salford Fortran */
f(((void *) &msg), &len);
}

How can I setup a Salford Fortran routine to be called from C where I can pass value arguments as well as reference arguments (e.g., the 'len' argument above)?

How can I setup a Salford Fortran routine to receive a string from C (e.g., the 'msg' argument above)?



Note that I know how to do this in Compaq/Digital Fortran ...

Compaq/Digital Fortran
----------------------

subroutine display [STDCALL] (msg,len)
implicit none
integer :: len
character*(len) :: msg [REFERENCE]
write(*,*) msg
end

typedef void (__stdcall * Callback_displayf)(const char *msg, int len);

void CallFortran_display(Callback_displayf f, const char *msg, int len)
{
/* I have a pointer to 'display' in 'f' from an earlier call from Compaq Fortran */
f(msg, len);
}
Back to top
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Thu Nov 03, 2005 2:22 am    Post subject: Calling Salford Fortran from C with value arguments and C st Reply with quote

David

In this context, scalar values (e.g. int, float, double) can only be passed by reference.

Fortran character arguments require an additional length argument which is hidden in the Fortran code but explicit in the C code. The following link shows a similar case but going the other way http://forums.silverfrost.com/forums/forum.asp?forumid=3&page=4&select=710#xx710xx

The STDCALL attribute provides a complicating factor. If you need to use STDCALL and F_STDCALL then you will almost certainly experience problems when more than one character variable is passed or when the character variable (with its length) is not the last argument.

Things become easier if you can use the Salford compiler SCC and SLINK. In any case you might make progress by doing some simple tests using SCC and SLINK. Avoid STDCALL initially. The MAP command with SLINK can provide useful diagnostics. When using STDCALL, the DECORATE command in SLINK can also provide useful diagnostic information. If you can understand assembly code then the /EXPLIST compiler command line switch might help you to see what is pushed on to the argument stack.

Some further information can be found in FTN95.chm under "Calling FTN95 from C/C++" but this may not answer all of your questions.
Back to top
View user's profile Send private message AIM Address
Anonymous
Guest





PostPosted: Thu Nov 03, 2005 5:00 am    Post subject: Calling Salford Fortran from C with value arguments and C st Reply with quote

Thanks.

David
Back to top
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General 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