C字符串到Fortran [英] C strings to Fortran

查看:107
本文介绍了C字符串到Fortran的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我知道这是一个常见话题,但我没有发现任何帖子

解决了我当前的问题。我正在使用Microsoft Visual C ++ 6.0(SP5),

和适用于Windows的英特尔Fortran 7.1编译器。


我正在尝试通过C我的Fortran代码的字符串。

这是代码(非常简单):


********** C打印.c列出**********

#include< stdio.h>


extern" C" {

void __stdcall PRINT_STRING(char *);

}


int main(无效)

{

char * cstring =" Hello World!" ;;

PRINT_STRING(cstring);

返回0;

}

********** Fortran print.f列表**********

子程序PRINT_STRING(fstring )

CHARACTER * 30 fstring

print *,''Fortran string:'',fstring

end

*********************************************


输出错误,我得到的结果如下:

" Fortran字符串:$"

(对于任何其他ascii字符,''$''可能会改变)


所以,我试过隐藏了-length方法,但链接器不喜欢

它:

" test.obj:错误LNK2001:未解析的外部符号_PRINT_STRING @ 8

Debug / test.exe:致命错误LNK1120:1未解析的外部

(我只将长度参数声明为C列表,如

中所写的一些帖子在这里)。


如果有人知道如何传递这些字符串,或者有一个奇迹

lib / function来转换那些C字符串(记住,我使用英特尔Fortran

编译器,文档中没有任何内容可以帮助

关于它......)。


我不能使用CHARACTER *(*),因为Fortran编译器是

抱怨错误531:变量CSTRING不能是值

伪参数使用CHARACTER (*)改为。 (即使我使用CHARACTER(*)

写的......)。


嘿,伙计们,帮助我!

很多很好


谢谢!

Ok, I know this is a common topic, but I didn''t find any post that
solves my current problem. I''m using Microsoft Visual C++ 6.0 (SP5),
and Intel Fortran 7.1 Compiler for Windows.

I''m trying to pass a C character string to my Fortran code.
Here is the code (a very simple one):

********** C print.c listing **********
#include <stdio.h>

extern "C" {
void __stdcall PRINT_STRING(char *);
}

int main(void)
{
char *cstring = "Hello World!";
PRINT_STRING(cstring);
return 0;
}
********** Fortran print.f listing **********
subroutine PRINT_STRING(fstring)
CHARACTER*30 fstring
print *,''Fortran string: '',fstring
end
*********************************************

The output is wrong, and I got something like:
" Fortran string: $"
(the ''$'' may change for any other ascii character)

So, I''ve tried the hidden-length method, but the linker doesn''t like
it:
"test.obj : error LNK2001: unresolved external symbol _PRINT_STRING@8
Debug/test.exe : fatal error LNK1120: 1 unresolved externals"
(I only declare the length parameter into the C listing as written in
some posts here).

If someone got an idea on how to pass those strings, or got a miracle
lib/function to convert those C strings (remember, I use Intel Fortran
Compiler and there is nothing into the documentation that may help
about it...).

I can''t neither use CHARACTER*(*) since the Fortran compiler is
complaining about "Error 531 : The variable CSTRING cannot be a value
dummy argument use CHARACTER(*) instead." (even if I use CHARACTER(*)
as written...).

Hey, dudes, help me!
Thanx a lot

Thanks!

推荐答案

"

( ''
"
(the ''


''可能会改变任何其他ascii字符)


所以,我尝试过隐藏长度的方法,但是链接器不喜欢

它:

" test.obj:错误LNK2001:未解析的外部符号_PRINT_STRING @ 8

调试/ test.exe:致命错误LNK1120:1个未解析的外部

(我只将长度参数声明为C列表,如

中的一些帖子所示)。


如果有人知道如何传递这些字符串,或者有一个奇迹

lib / function来转换那些C字符串(请记住,我使用英特尔Fortran

编译器,文档中没有任何内容可以帮助

关于它......)。


我不能它使用CHARACTER *(*),因为Fortran编译器是抱怨错误531:变量CSTRING不能是一个值

伪参数使用CHARACTER(*) " (即使我使用CHARACTER(*)

写的......)。


嘿,伙计们,帮助我!

很多很好


谢谢!
'' may change for any other ascii character)

So, I''ve tried the hidden-length method, but the linker doesn''t like
it:
"test.obj : error LNK2001: unresolved external symbol _PRINT_STRING@8
Debug/test.exe : fatal error LNK1120: 1 unresolved externals"
(I only declare the length parameter into the C listing as written in
some posts here).

If someone got an idea on how to pass those strings, or got a miracle
lib/function to convert those C strings (remember, I use Intel Fortran
Compiler and there is nothing into the documentation that may help
about it...).

I can''t neither use CHARACTER*(*) since the Fortran compiler is
complaining about "Error 531 : The variable CSTRING cannot be a value
dummy argument use CHARACTER(*) instead." (even if I use CHARACTER(*)
as written...).

Hey, dudes, help me!
Thanx a lot

Thanks!


ac **** @ netcourrier.com (约翰史密斯)写道:

#好的,我知道这是一个常见话题,但我没有找到任何帖子

#解决了我当前的问题。我正在使用Microsoft Visual C ++ 6.0(SP5),

#和适用于Windows的英特尔Fortran 7.1编译器。


应该详细说明呼叫约定编译器

文档。如果您还没有编译器参考指南,

您可以尝试探索
http://support.intel.com/support/per...ows/manual.htm


http:// www。 intel.com/software/produc...cs/for_prg.htm

可下载副本。我见过的每个编译器文档

都有这样的部分。


-

Derk Gwen http://derkgwen.250free.com/html/index.html

我认为这有点个人化;我不认为我应该回答这个问题。
ac****@netcourrier.com (John Smith) wrote:
# Ok, I know this is a common topic, but I didn''t find any post that
# solves my current problem. I''m using Microsoft Visual C++ 6.0 (SP5),
# and Intel Fortran 7.1 Compiler for Windows.

That should be detailed in the "Calling Conventions" of the compiler
documentation. If you don''t already have the compiler reference guide,
you can try poking around
http://support.intel.com/support/per...ows/manual.htm
or
http://www.intel.com/software/produc...cs/for_prg.htm
for a downloadable copy. Every compiler documentation I have ever seen
has such a section.

--
Derk Gwen http://derkgwen.250free.com/html/index.html
I think that''s kinda of personal; I don''t think I should answer that.


这篇关于C字符串到Fortran的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆