<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Fortran on Peczenyj's Blog</title><link>http://pacman.blog.br/categories/fortran/</link><description>Recent content in Fortran on Peczenyj's Blog</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Mon, 02 Jul 2007 11:48:00 -0300</lastBuildDate><atom:link href="http://pacman.blog.br/categories/fortran/atom.xml" rel="self" type="application/rss+xml"/><item><title>O melhor de dois mundos: C e Fortran</title><link>http://pacman.blog.br/blog/2007/07/02/o-melhor-de-dois-mundos-c-e-fortran/</link><pubDate>Mon, 02 Jul 2007 11:48:00 -0300</pubDate><guid>http://pacman.blog.br/blog/2007/07/02/o-melhor-de-dois-mundos-c-e-fortran/</guid><description>&lt;div class='post'>
C é uma ótima linguagem de programação, simples e clara.&lt;br />Fortran, para problemas matemáticos, é imbativel!&lt;br />&lt;br />Que tal usar o melhor dos dois mundos com este &lt;a href="http://www.yolinux.com/TUTORIALS/LinuxTutorialMixingFortranAndC.html">tutorial&lt;/a>?&lt;br />&lt;br />Vejamos o exemplo abaixo:&lt;br />&lt;br />Arquivo testC.cpp&lt;br />&lt;pre>&lt;code>#include &lt;iostream>&lt;br />&lt;br />using namespace std;&lt;br />&lt;br />extern"C" {&lt;br />void fortfunc_(int *ii, float *ff);&lt;br />}&lt;br />&lt;br />main()&lt;br />{&lt;br />&lt;br /> int ii=5;&lt;br /> float ff=5.5;&lt;br />&lt;br /> fortfunc_(&amp;ii, &amp;ff);&lt;br />&lt;br /> return 0;&lt;br />}&lt;/code>&lt;/pre>&lt;br />&lt;br />Arquivo testF.f&lt;br />&lt;pre>&lt;code> subroutine fortfunc(ii,ff)&lt;br /> integer ii&lt;br /> real*4 ff&lt;br />&lt;br /> write(6,100) ii, ff&lt;br /> 100 format('ii=',i2,' ff=',f6.3)&lt;br />&lt;br /> return&lt;br /> end&lt;/code>&lt;/pre>&lt;br />&lt;br />Compilando&lt;br />&lt;br />&lt;pre>$ f77 -c testF.f&lt;br />$ g++ -c testC.cpp&lt;br />$ g++ -o test testF.o testC.o -lg2c&lt;/pre>&lt;br />&lt;br />Executando&lt;br />&lt;br />&lt;pre>$ ./test&lt;br />ii= 5 ff= 5.500&lt;/pre>&lt;br />&lt;br />Aceito sugestões, agora que não tenho muita coisa para fazer em Fortran.&lt;/div></description></item></channel></rss>