<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Mixing C code in a Fortran Project? in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixing-C-code-in-a-Fortran-Project/m-p/783993#M29142</link>
    <description>Microsoft changed the preferred (default) ABI from STDCALL to CDECL right at the time CVF support was winding down (over a decade ago). As you indicated, the @&lt;NUMBER of="" bytes=""&gt; scheme went away with that change, and the systems don't mix. Unless you have some requirement to struggle with an ancient library for which you don't have source code, you should go with current techniques, including USE iso_c_binding for data type and function name consistency between ifort and MSVC or ICL. As Steve mentioned, there are examples of C interface in the documents.&lt;/NUMBER&gt;</description>
    <pubDate>Sun, 20 Mar 2011 02:26:09 GMT</pubDate>
    <dc:creator>TimP</dc:creator>
    <dc:date>2011-03-20T02:26:09Z</dc:date>
    <item>
      <title>Mixing C code in a Fortran Project?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixing-C-code-in-a-Fortran-Project/m-p/783987#M29136</link>
      <description>I have a small C program which converts between IEEE floating point and the old IBM float format (which are actually remarkably similar, though not the same). In Visual Studio 2000 and CVF, I just added it to the project and Visual Studio figured it out, compiled it and linked it. &lt;BR /&gt;&lt;BR /&gt;Visual Studio 2010 seems to recognize it as C code, the text colors are correct and the icon in the file view tree shows it as a C program. However it does not seem to compile. I did buy the VS 2010 and Help/About does show the C++ compiler.&lt;BR /&gt;&lt;BR /&gt;Do I need a custom build step and what is that?&lt;BR /&gt;&lt;BR /&gt;Or is there another way to convert between IEEE and the old IBM floating point formats?&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;&lt;BR /&gt;Charles</description>
      <pubDate>Sat, 12 Mar 2011 05:23:16 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixing-C-code-in-a-Fortran-Project/m-p/783987#M29136</guid>
      <dc:creator>chstoyer</dc:creator>
      <dc:date>2011-03-12T05:23:16Z</dc:date>
    </item>
    <item>
      <title>Mixing C code in a Fortran Project?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixing-C-code-in-a-Fortran-Project/m-p/783988#M29137</link>
      <description>That was Visual Studio 98 you used with CVF.&lt;BR /&gt;&lt;BR /&gt;Microsoft no longer supports mixed-language projects, so the way you have to do this now is create a Solution with two projects, one for your C code and one for your Fortran code. Whichever is the main program should be an executable project and the other a static library project. Use the Project &amp;gt; Dependences menu to make the library a dependent of the executable. See also &lt;A href="http://software.intel.com/en-us/articles/configuring-visual-studio-for-mixed-language-applications"&gt;configuring Visual C++ for mixed-language applications&lt;/A&gt;.&lt;BR /&gt;&lt;BR /&gt;Take a look at the mixed-language samples provided.</description>
      <pubDate>Sat, 12 Mar 2011 16:03:35 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixing-C-code-in-a-Fortran-Project/m-p/783988#M29137</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2011-03-12T16:03:35Z</dc:date>
    </item>
    <item>
      <title>Mixing C code in a Fortran Project?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixing-C-code-in-a-Fortran-Project/m-p/783989#M29138</link>
      <description>I actually was (am) using Visual Studio 2000. We were actively developing C++ Foundation Class projects 10 or so years ago and out of several hundred CDs, I have a handfull which I found useful, mostly Office and Visual Studio 2000. But all this dies with Windows 7.&lt;BR /&gt;&lt;BR /&gt;The "configuring Visual C++ for mixed-language applications" actually addresses Fortran libraries with C++ main programs, which is different from what I am trying to do. I have a C code of several lines containing two functions. I tried to create a project, but I cannot seem to find anything that looks like creating a C language static library, which is what I think I want. I see that for Fortran, but not for C. What kind of project do I need?&lt;BR /&gt;&lt;BR /&gt;Too bad Microsoft abandonded the mixed language programming. Maybe they got too many languages and couldn't manage it anymore.&lt;BR /&gt;&lt;BR /&gt;Thanks in advance,&lt;BR /&gt;&lt;BR /&gt;Charles</description>
      <pubDate>Mon, 14 Mar 2011 07:30:50 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixing-C-code-in-a-Fortran-Project/m-p/783989#M29138</guid>
      <dc:creator>chstoyer</dc:creator>
      <dc:date>2011-03-14T07:30:50Z</dc:date>
    </item>
    <item>
      <title>Mixing C code in a Fortran Project?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixing-C-code-in-a-Fortran-Project/m-p/783990#M29139</link>
      <description>If you have already compiled the C-code in the past and it links OK into a Windows program and runs OK, I think you should be able to use the .OBJ file that the earlier C-compiler produced. Just add it to your Fortran program and see if it links OK.&lt;BR /&gt;&lt;BR /&gt;If there is name mismatch and the linker cannot find the C-functions/routines, do a DUMPBIN on the C .OBJ file to list the symbol table and see what the C routines are called and then match up your Fortran calls to reference the same names using the ALIAS atribute and to match the calling convention used by the C code. In order to do this, you will need to generate an interface block for your C functions/subroutines for use in your Fortran to let the Fortran compiler know what it is to expect (ALIAS and calling convention) when you reference a C function/routine that is to be linked from your C .OBJ file.</description>
      <pubDate>Mon, 14 Mar 2011 11:23:47 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixing-C-code-in-a-Fortran-Project/m-p/783990#M29139</guid>
      <dc:creator>anthonyrichards</dc:creator>
      <dc:date>2011-03-14T11:23:47Z</dc:date>
    </item>
    <item>
      <title>Mixing C code in a Fortran Project?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixing-C-code-in-a-Fortran-Project/m-p/783991#M29140</link>
      <description>Charles,&lt;BR /&gt;&lt;BR /&gt;Microsoft never released a "Visual Studio 2000". It went from '98 to 2002.&lt;BR /&gt;&lt;BR /&gt;To create a C static library project, use the Win32 project type and then the "Win32 Project" template. There you can select a static library. You will want to ensure that the run-time library settings are the same in the C and Fortran projects. In C/C++, this is under Code Generation.</description>
      <pubDate>Mon, 14 Mar 2011 14:28:12 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixing-C-code-in-a-Fortran-Project/m-p/783991#M29140</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2011-03-14T14:28:12Z</dc:date>
    </item>
    <item>
      <title>Mixing C code in a Fortran Project?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixing-C-code-in-a-Fortran-Project/m-p/783992#M29141</link>
      <description>&lt;DIV id="tiny_quote"&gt;&lt;DIV style="margin-left: 2px; margin-right: 2px;"&gt;Quoting &lt;A jquery1300580457781="67" rel="/en-us/services/profile/quick_profile.php?is_paid=&amp;amp;user_id=336209" href="https://community.intel.com/en-us/profile/336209/" class="basic"&gt;Steve Lionel (Intel)&lt;/A&gt;&lt;/DIV&gt;&lt;DIV style="background-color: #e5e5e5; margin-left: 2px; margin-right: 2px; border: 1px inset; padding: 5px;"&gt;&lt;I&gt;Charles,&lt;BR /&gt;&lt;BR /&gt;Microsoft never released a "Visual Studio 2000". It went from '98 to 2002.&lt;BR /&gt;&lt;BR /&gt;Sorry, the real name seems to be Visual Studio 6.0 Enterprise Edition.&lt;BR /&gt;&lt;BR /&gt;To create a C static library project, use the Win32 project type and then the "Win32 Project" template. There you can select a static library. You will want to ensure that the run-time library settings are the same in the C and Fortran projects. In C/C++, this is under Code Generation.&lt;BR /&gt;&lt;/I&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;Sorry, the real name seems to be Visual Studio 6.0 Enterprise Edition.&lt;BR /&gt;&lt;BR /&gt;OK, I decided to try to go the way of including the obj file rather than creating a library for a single module, but I am still having problems with this and alsowith a library I am trying to use. Fortran looks for "_FLOATTOIBM" whereas OBJ compiled from the VS 2010 C++ compiler is called "&lt;A href="mailto:FLOATTOIBM@16"&gt;FLOATTOIBM@16&lt;/A&gt;". I can add the underscore and then it is called "&lt;A href="mailto:_FLOATTOIBM@16"&gt;_FLOATTOIBM@16&lt;/A&gt;" and it is still not recognized. If I use the OBJ compiled with Visual C++ 6.0, it doesn't work either, it also has the @ 16.&lt;BR /&gt;&lt;BR /&gt;For the library, the symbol searched for in the Fortran is "_KECHK32" but the lib file (I am trying to import from a DLL eventually) calls it "&lt;A href="mailto:_KECHK32@4"&gt;_KECHK32@4&lt;/A&gt;".&lt;BR /&gt;&lt;BR /&gt;I am getting this information by looking at the obj or lib files with a HEX editor.&lt;BR /&gt;&lt;BR /&gt;Going back to the CVF code, the "@16" is present in both calling and called OBJ files. I remember if you called a routine in CVF with the right name but wrong number of arguments, it would complain about not finding "&lt;A href="mailto:SUB@32"&gt;SUB@32&lt;/A&gt;" or whatever. So the IVF does not differentiate on number of arguments?&lt;BR /&gt;&lt;BR /&gt;The really important thing is the library DLL import. The C code can probably be implemented in Fortran if this turns out to be a nightmare, but there must be some way to call C from Fortran. I did look at the C compiler options and selected STD_CALL, which was not originally selected, but this did not help.&lt;BR /&gt;&lt;BR /&gt;So it really seems to be the lack of the @ sign and the byte count of the argument list that is the problem.&lt;BR /&gt;&lt;BR /&gt;I tried the !$DEC ALIAS FLOATTOIBM &lt;A href="mailto:FLOATTOIBM@16"&gt;FLOATTOIBM@16&lt;/A&gt; statement and that did not help either.&lt;BR /&gt;&lt;BR /&gt;Any suggestions appreciated.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;&lt;BR /&gt;Charles&lt;/P&gt;</description>
      <pubDate>Sun, 20 Mar 2011 00:40:20 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixing-C-code-in-a-Fortran-Project/m-p/783992#M29141</guid>
      <dc:creator>chstoyer</dc:creator>
      <dc:date>2011-03-20T00:40:20Z</dc:date>
    </item>
    <item>
      <title>Mixing C code in a Fortran Project?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixing-C-code-in-a-Fortran-Project/m-p/783993#M29142</link>
      <description>Microsoft changed the preferred (default) ABI from STDCALL to CDECL right at the time CVF support was winding down (over a decade ago). As you indicated, the @&lt;NUMBER of="" bytes=""&gt; scheme went away with that change, and the systems don't mix. Unless you have some requirement to struggle with an ancient library for which you don't have source code, you should go with current techniques, including USE iso_c_binding for data type and function name consistency between ifort and MSVC or ICL. As Steve mentioned, there are examples of C interface in the documents.&lt;/NUMBER&gt;</description>
      <pubDate>Sun, 20 Mar 2011 02:26:09 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixing-C-code-in-a-Fortran-Project/m-p/783993#M29142</guid>
      <dc:creator>TimP</dc:creator>
      <dc:date>2011-03-20T02:26:09Z</dc:date>
    </item>
    <item>
      <title>Mixing C code in a Fortran Project?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixing-C-code-in-a-Fortran-Project/m-p/783994#M29143</link>
      <description>Here is an example using, instead of the name mangling conventions of Intel Fortran and Microsoft C, the C-interoperability features of Fortran 200X:&lt;BR /&gt;&lt;BR /&gt;The C-function that converts a 32-bit IBM 360 float, passed as a 32-bit word, returning a &lt;SPAN style="text-decoration: underline;"&gt;double&lt;/SPAN&gt;:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE&gt;[cpp]#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;MATH.H&gt;&lt;BR /&gt;&lt;BR /&gt;struct ibm32{&lt;BR /&gt;   unsigned frac : 24;&lt;BR /&gt;   unsigned biasexp : 7;&lt;BR /&gt;   unsigned s : 1;&lt;BR /&gt;   };&lt;BR /&gt;&lt;BR /&gt;double ibm2dble(struct ibm32 w){&lt;BR /&gt;double absval=ldexp((double)w.frac,4*(w.biasexp-64)-24);&lt;BR /&gt;printf("  IBM FLOAT FRAC = %08Xn  IBM FLOAT EXPO = %08Xn  IBM FLOAT SIGN = %1Xn",&lt;BR /&gt;       w.frac,w.biasexp,w.s);&lt;BR /&gt;return w.s ? -absval : + absval;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;/*&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;&lt;BR /&gt;union ibm32u{&lt;BR /&gt;   struct ibm32 w;&lt;BR /&gt;   long l;&lt;BR /&gt;   };&lt;BR /&gt;&lt;BR /&gt;main(){&lt;BR /&gt;union ibm32u uw;&lt;BR /&gt;uw.l=0xC276A000;&lt;BR /&gt;printf("%22.15e",ibm2float(uw.w));&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;*/&lt;BR /&gt;[/cpp]&lt;/STDIO.H&gt;&lt;/MATH.H&gt;&lt;/STDIO.H&gt;&lt;/PRE&gt; The Fortran main program, which calls the C function using F2003 C-interoperability, and the example from &lt;A href="http://en.wikipedia.org/wiki/IBM_Floating_Point_Architecture:" target="_blank"&gt;http://en.wikipedia.org/wiki/IBM_Floating_Point_Architecture:&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE&gt;[fortran]program ibm2ieee&lt;BR /&gt;use iso_c_binding&lt;BR /&gt;&lt;BR /&gt;interface&lt;BR /&gt;  real(c_double) function ibm2dble(l) bind(C)&lt;BR /&gt;  use iso_c_binding&lt;BR /&gt;  integer(c_int32_t), value :: l&lt;BR /&gt;  end function ibm2dble&lt;BR /&gt;end interface&lt;BR /&gt;&lt;BR /&gt;integer(c_int32_t) :: l=Z'C276A000';&lt;BR /&gt;&lt;BR /&gt;write(*,*)' Decimal value of IBM FLOAT word = ',ibm2dble(l)&lt;BR /&gt;end program ibm2ieee&lt;BR /&gt;[/fortran]&lt;/PRE&gt; Compile the C function to an .OBJ file, and compile the Fortran code to an .EXE:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE&gt;[bash]s:LANG:&amp;gt; cl /MD /c ibm32.c&lt;BR /&gt;s:LANG:&amp;gt; ifort /MD ibmdbl.f90 ibm32.obj&lt;BR /&gt;[/bash]&lt;/PRE&gt; Run the program and compare the result to that in the Wikipedia article:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE&gt;[bash]s:LANG&amp;gt;ibmdbl&lt;BR /&gt;  IBM FLOAT FRAC = 0076A000&lt;BR /&gt;  IBM FLOAT EXPO = 00000042&lt;BR /&gt;  IBM FLOAT SIGN = 1&lt;BR /&gt;  Decimal value of IBM FLOAT word =   -118.625000000000&lt;BR /&gt;[/bash]&lt;/PRE&gt;</description>
      <pubDate>Sun, 20 Mar 2011 02:45:33 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixing-C-code-in-a-Fortran-Project/m-p/783994#M29143</guid>
      <dc:creator>mecej4</dc:creator>
      <dc:date>2011-03-20T02:45:33Z</dc:date>
    </item>
    <item>
      <title>Mixing C code in a Fortran Project?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixing-C-code-in-a-Fortran-Project/m-p/783995#M29144</link>
      <description>&lt;P&gt;Steve and Mecej4,&lt;BR /&gt;&lt;BR /&gt;I was afraid there would not be good news.&lt;BR /&gt;&lt;BR /&gt;I am sure I can find a way to recompile my C code to get it to work with IVF. Or find another way to convert between (I need to go both ways) IEEE and IBM float (single precision only). &lt;BR /&gt;&lt;BR /&gt;But I do have an antique library (or did you say "ancient") for which I may not be able to get a modern replacement. This is the copy protection dongle interface and means I either stay in CVF for existing products or ask people all over the world to exchange keys for new ones at substantial expense to either me or them.&lt;BR /&gt;&lt;BR /&gt;As you know, staying in CVF means nursing Win XP machines for the duration...&lt;BR /&gt;&lt;BR /&gt;So, can I use the Interface&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;interface &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;double precision function ibm2dble(l) bind(C) &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;use iso_c_binding &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;integer,value :: l &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;end function ibm2dble &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;end interface &lt;/STRONG&gt;&lt;/P&gt;&lt;BR /&gt;in some way to link with the existing &lt;A href="mailto:KECHK32@4"&gt;KECHK32@4&lt;/A&gt;? If so, what binding would I use? STDCALL?&lt;BR /&gt;&lt;BR /&gt;Are there examples of this?&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;&lt;BR /&gt;Charles</description>
      <pubDate>Mon, 21 Mar 2011 01:34:42 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixing-C-code-in-a-Fortran-Project/m-p/783995#M29144</guid>
      <dc:creator>chstoyer</dc:creator>
      <dc:date>2011-03-21T01:34:42Z</dc:date>
    </item>
    <item>
      <title>Mixing C code in a Fortran Project?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixing-C-code-in-a-Fortran-Project/m-p/783996#M29145</link>
      <description>From your comments I feel that with more awareness of the issues concerning mixed language projects you could make a better decision. Merely trying different combinations and compiler options without understanding the implications may, once in a while, solve or &lt;I&gt;appear&lt;/I&gt; to solve the problem, but the number of combinations are too many to try and the results will always be open to suspicion.&lt;BR /&gt;&lt;BR /&gt;You should read about and understand this point about C-interoperability from the standpoint of the Fortran standard: &lt;BR /&gt;&lt;BR /&gt; it is a specification to follow with a &lt;SPAN style="text-decoration: underline;"&gt;definite pair&lt;/SPAN&gt; of C and Fortran "processors", i.e., compilers, with guaranteed success, at least as to interoperability. &lt;BR /&gt;&lt;BR /&gt;Intel Fortran and MSVC (or Intel C) are one such pair; GFortran and GCC are another such pair. On the other hand, it is almost possible to guarantee that an arbitrary pair, e.g., IFort and GCC or Absoft Fortran and ICC, &lt;SPAN style="text-decoration: underline;"&gt;will not work&lt;/SPAN&gt;.&lt;BR /&gt;&lt;BR /&gt;Typically, the C compiler of the defined pair knows nothing about and does not care about being called from or calling into Fortran -- there is no Fortran Interoperability section in the C standards. Therefore, the Fortran compiler in the defined pair has to produce .OBJ files that are suitable for linking with the C .OBJ files. Given the diversity of calling and name decoration conventions, it is understandable that there is only one specified compatible C compiler -- it is called the "Companion Processor" in the Fortran standards.&lt;BR /&gt;&lt;BR /&gt;Similar comments can be made about compiler options such as /Gm and /iface:xxx. Typically, explicitly declared attributes such as _cdecl or _stdcall override compiler options. Neither the Fortran nor the C compiler does anything to confirm whether the &lt;I&gt;other&lt;/I&gt; compiler was used with those options that are essential for interoperability; doing so falls on the the shouders of the programmer.&lt;BR /&gt;&lt;BR /&gt;We do not know what the contents of this ancient library of yours are, beyond the IEEE &amp;lt;--&amp;gt; IBM-360 floating point conversions. Chances are very good that you can assemble a new library from pieces available freely. Just as 16-bit code no longer runs on W7, your old library will become unusable one of these days. &lt;BR /&gt;&lt;BR /&gt;By the way, CVF 6.6 works fine in command-line mode on W7-X64. It is the GUI and installers that fail.</description>
      <pubDate>Mon, 21 Mar 2011 09:01:21 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixing-C-code-in-a-Fortran-Project/m-p/783996#M29145</guid>
      <dc:creator>mecej4</dc:creator>
      <dc:date>2011-03-21T09:01:21Z</dc:date>
    </item>
    <item>
      <title>Mixing C code in a Fortran Project?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixing-C-code-in-a-Fortran-Project/m-p/783997#M29146</link>
      <description>You MUST supply a correct interface block to any external subroutine or function if you want to stand any chance of the compiler linking to it correctly.&lt;BR /&gt;&lt;BR /&gt;Your attempt at using the 'ALIAS' attribute looks wrong.&lt;BR /&gt;It should be along the lines of the following (the @16 implies FOUR arguments are required). I'll assume that&lt;BR /&gt;it is a subroutine you are calling (just swap REAL(4) FUNCTION - or whatever type - for SUBROUTINE and END FUNCTION for END SUBROUTINE if it is a function call)&lt;BR /&gt;&lt;BR /&gt;INTERFACE&lt;BR /&gt;Subroutine FLOATTOIBM(arg1,arg2,arg3,arg4)&lt;BR /&gt; !DEC$ ATTRIBUTES STDCALL, ALIAS:'_&lt;A&gt;FLOATTOIBM@16&lt;/A&gt;' :: &lt;A&gt;FLOATTOIBM&lt;/A&gt;&lt;BR /&gt; !DEC$ ATTRIBUTES REFERENCE :: arg1&lt;BR /&gt; !DEC$ ATTRIBUTES REFERENCE :: arg2&lt;BR /&gt; !DEC$ ATTRIBUTES REFERENCE :: arg3&lt;BR /&gt; !DEC$ ATTRIBUTES REFERENCE :: arg4&lt;BR /&gt; !Correctly define the argument types here...for example&lt;BR /&gt; REAL(4) arg1,arg2&lt;BR /&gt; INTEGER(4) arg3,arg4&lt;BR /&gt;END SUBROUTINE FLOATTOIBM&lt;BR /&gt;END INTERFACE&lt;BR /&gt;&lt;BR /&gt;The 'ALIAS' specifies that the aliased name for the (automatic) uppercase Fortran name 'FLOATTOIBM' is '_&lt;A&gt;FLOATTOIBM@16', and this is the name to be searched for when linking.&lt;/A&gt; It is important that the ALIAS anem agrees with the case of the symbol name in the C- object file, in ALL details.&lt;BR /&gt;</description>
      <pubDate>Mon, 21 Mar 2011 10:44:46 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixing-C-code-in-a-Fortran-Project/m-p/783997#M29146</guid>
      <dc:creator>anthonyrichards</dc:creator>
      <dc:date>2011-03-21T10:44:46Z</dc:date>
    </item>
    <item>
      <title>Mixing C code in a Fortran Project?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixing-C-code-in-a-Fortran-Project/m-p/783998#M29147</link>
      <description>I want to clarify a few things in this thread.&lt;BR /&gt;&lt;BR /&gt;1. If you can call something from CVF you can call it from Intel Visual Fortran. Period. At most you may need to construct a proper INTERFACE block.&lt;BR /&gt;2. The major change in calling between CVF and IVF is the default calling convention. CVF used STDCALL with string lengths immediately following the string address in the argument list, IVF uses C and puts the string lengths at the end. Both compilers have directives and options to do it the "other" way.&lt;BR /&gt;3. You should (almost) never add the @n suffix in an ALIAS. This is why we invented the DECORATE attribute. So looking at Anthony's example, one might write:&lt;BR /&gt;&lt;BR /&gt;!DEC$ ATTRIBUTES STDCALL, REFERENCE, DECORATE, ALIAS:"FLOATTOIBM" :: FLOATTOIBM&lt;BR /&gt;&lt;BR /&gt;The compiler will add the correct decoration, including leading underscore and trailing @n. Note that these naming conventions are different when building for x64 - the compiler will do the right thing.&lt;BR /&gt;4. Microsoft did not change calling conventions - the Win32 API as well as the interpretive languages use STDCALL almost exclusively, but the MS C compiler defaults to the C mechanism. If you want to call a STDCALL routine from C you need to add __stdcall to the routine header.</description>
      <pubDate>Mon, 21 Mar 2011 15:46:08 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixing-C-code-in-a-Fortran-Project/m-p/783998#M29147</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2011-03-21T15:46:08Z</dc:date>
    </item>
    <item>
      <title>Mixing C code in a Fortran Project?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixing-C-code-in-a-Fortran-Project/m-p/783999#M29148</link>
      <description>Thanks to both of you guys for your help. A lot of food for thought hereI will play with the IEEE float to IBM float as it would be instructive. but I am sure that cat could be skinned another way. My real problem is talking to USB copy protection keys and if I can't get a solution from the key manufacturer, I am stuck.&lt;BR /&gt;&lt;BR /&gt;I think if I can figure out how to get IBMtoFloat to work, I can get the key interface software to work.&lt;BR /&gt;&lt;BR /&gt;I have never used any of this interface stuff, so this is new to me.&lt;BR /&gt;&lt;BR /&gt;Again, I have source for the IBMtoFloat, so I am not stuck there, it is with the ancient library for which I have no source that is the problem.&lt;BR /&gt;&lt;BR /&gt;I will come back and let you know if I get it to work.&lt;BR /&gt;&lt;BR /&gt;BTW, here is the code for the IBM/IEEE code FYI&lt;BR /&gt;&lt;BR /&gt;Charles&lt;BR /&gt;&lt;BR /&gt;&lt;P&gt;/* Assumes sizeof(int) == 4 */&lt;/P&gt;&lt;P&gt;extern void __stdcall _FLOATTOIBM(int from[], int to[], int n, int endian)&lt;/P&gt;&lt;P&gt;/**********************************************************************&lt;/P&gt;&lt;P&gt;float_to_ibm - convert between 32 bit IBM and IEEE floating numbers&lt;/P&gt;&lt;P&gt;*********************************************************************** &lt;/P&gt;&lt;P&gt;Input:&lt;/P&gt;&lt;P&gt;from input vector&lt;/P&gt;&lt;P&gt;n number of floats in vectors&lt;/P&gt;&lt;P&gt;endian =0 for little endian machine, =1 for big endian machines&lt;/P&gt;&lt;P&gt;Output:&lt;/P&gt;&lt;P&gt;to output vector, can be same as input vector&lt;/P&gt;&lt;P&gt;*********************************************************************** &lt;/P&gt;&lt;P&gt;Notes:&lt;/P&gt;&lt;P&gt;Up to 3 bits lost on IEEE -&amp;gt; IBM&lt;/P&gt;&lt;P&gt;IBM -&amp;gt; IEEE may overflow or underflow, taken care of by &lt;/P&gt;&lt;P&gt;substituting large number or zero&lt;/P&gt;&lt;P&gt;Only integer shifting and masking are used.&lt;/P&gt;&lt;P&gt;*********************************************************************** &lt;/P&gt;&lt;P&gt;Credits: CWP: Brian Sumner&lt;/P&gt;&lt;P&gt;***********************************************************************/&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;register int fconv, fmant, i, t;&lt;/P&gt;&lt;P&gt;for (i=0;i&lt;N&gt;&lt;/N&gt;&lt;/P&gt;&lt;P&gt;fconv = from&lt;I&gt;;&lt;/I&gt;&lt;/P&gt;&lt;P&gt;if (fconv) {&lt;/P&gt;&lt;P&gt;fmant = (0x007fffff &amp;amp; fconv) | 0x00800000;&lt;/P&gt;&lt;P&gt;t = (int) ((0x7f800000 &amp;amp; fconv) &amp;gt;&amp;gt; 23) - 126;&lt;/P&gt;&lt;P&gt;while (t &amp;amp; 0x3) { ++t; fmant &amp;gt;&amp;gt;= 1; }&lt;/P&gt;&lt;P&gt;fconv = (0x80000000 &amp;amp; fconv) | (((t&amp;gt;&amp;gt;2) + 64) &amp;lt;&amp;lt; 24) | fmant;&lt;/P&gt;&lt;P&gt;if(endian==0)&lt;/P&gt;&lt;P&gt;fconv = (fconv&amp;lt;&amp;lt;24) | ((fconv&amp;gt;&amp;gt;24)&amp;amp;0xff) |&lt;/P&gt;&lt;P&gt;((fconv&amp;amp;0xff00)&amp;lt;&amp;lt;8) | ((fconv&amp;amp;0xff0000)&amp;gt;&amp;gt;8);&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;to&lt;I&gt; = fconv;&lt;/I&gt;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;return;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;extern void __stdcall _IBMTOFLOAT(int from[], int to[], int n, int endian)&lt;/P&gt;&lt;P&gt;/***********************************************************************&lt;/P&gt;&lt;P&gt;ibm_to_float - convert between 32 bit IBM and IEEE floating numbers&lt;/P&gt;&lt;P&gt;************************************************************************&lt;/P&gt;&lt;P&gt;Input::&lt;/P&gt;&lt;P&gt;from input vector&lt;/P&gt;&lt;P&gt;to output vector, can be same as input vector&lt;/P&gt;&lt;P&gt;endian byte order =0 little endian (DEC, PC's)&lt;/P&gt;&lt;P&gt;=1 other systems &lt;/P&gt;&lt;P&gt;************************************************************************* &lt;/P&gt;&lt;P&gt;Notes:&lt;/P&gt;&lt;P&gt;Up to 3 bits lost on IEEE -&amp;gt; IBM&lt;/P&gt;&lt;P&gt;Assumes sizeof(int) == 4&lt;/P&gt;&lt;P&gt;IBM -&amp;gt; IEEE may overflow or underflow, taken care of by &lt;/P&gt;&lt;P&gt;substituting large number or zero&lt;/P&gt;&lt;P&gt;Only integer shifting and masking are used.&lt;/P&gt;&lt;P&gt;************************************************************************* &lt;/P&gt;&lt;P&gt;Credits: CWP: Brian Sumner, c.1985&lt;/P&gt;&lt;P&gt;*************************************************************************/&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;register int fconv, fmant, i, t;&lt;/P&gt;&lt;P&gt;for (i=0;i&lt;N&gt;&lt;/N&gt;&lt;/P&gt;&lt;P&gt;fconv = from&lt;I&gt;;&lt;/I&gt;&lt;/P&gt;&lt;P&gt;if (fconv) {&lt;/P&gt;&lt;P&gt;/* if little endian, i.e. endian=0 do this */&lt;/P&gt;&lt;P&gt;if (endian==0) fconv = (fconv&amp;lt;&amp;lt;24) | ((fconv&amp;gt;&amp;gt;24)&amp;amp;0xff) |&lt;/P&gt;&lt;P&gt;((fconv&amp;amp;0xff00)&amp;lt;&amp;lt;8) | ((fconv&amp;amp;0xff0000)&amp;gt;&amp;gt;8);&lt;/P&gt;&lt;P&gt;fmant = 0x00ffffff &amp;amp; fconv;&lt;/P&gt;&lt;P&gt;if(fmant){&lt;/P&gt;&lt;P&gt;t = (int) ((0x7f000000 &amp;amp; fconv) &amp;gt;&amp;gt; 22) - 130;&lt;/P&gt;&lt;P&gt;while (!(fmant &amp;amp; 0x00800000)) { --t; fmant &amp;lt;&amp;lt;= 1; }&lt;/P&gt;&lt;P&gt;if (t &amp;gt; 254) fconv = (0x80000000 &amp;amp; fconv) | 0x7f7fffff;&lt;/P&gt;&lt;P&gt;else if (t &amp;lt;= 0) fconv = 0;&lt;/P&gt;&lt;P&gt;else fconv = (0x80000000 &amp;amp; fconv) |(t &amp;lt;&amp;lt; 23)|(0x007fffff &amp;amp; fmant);&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;else fconv=0;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;to&lt;I&gt; = fconv;&lt;/I&gt;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;return;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2011 16:33:33 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixing-C-code-in-a-Fortran-Project/m-p/783999#M29148</guid>
      <dc:creator>chstoyer</dc:creator>
      <dc:date>2011-03-21T16:33:33Z</dc:date>
    </item>
    <item>
      <title>Mixing C code in a Fortran Project?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixing-C-code-in-a-Fortran-Project/m-p/784000#M29149</link>
      <description>&lt;STRONG&gt;I would like to thank all those who helped. I got both my C obj and the DLL import STDCALL to work.&lt;BR /&gt;&lt;BR /&gt;For the C obj file (posted earlier) I used&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;P&gt;INTERFACE&lt;BR /&gt;Subroutine FLOATTOIBM(arg1,arg2,arg3,arg4)&lt;BR /&gt;!DEC$ ATTRIBUTES STDCALL, DECORATE, ALIAS:"FLOATTOIBM" :: FLOATTOIBM&lt;BR /&gt;!DEC$ ATTRIBUTES REFERENCE :: arg1&lt;BR /&gt;!DEC$ ATTRIBUTES REFERENCE :: arg2&lt;BR /&gt;!DEC$ ATTRIBUTES VALUE :: arg3&lt;BR /&gt;!DEC$ ATTRIBUTES VALUE :: arg4&lt;BR /&gt;!Correctly define the argument types here...&lt;BR /&gt;REAL(4) arg1(:),arg2(:)&lt;BR /&gt;INTEGER(4) arg3,arg4&lt;BR /&gt;END SUBROUTINE FLOATTOIBM&lt;BR /&gt;END INTERFACE&lt;BR /&gt;&lt;STRONG&gt;&lt;BR /&gt;Calling with&lt;BR /&gt;&lt;BR /&gt;CALL FloatToIbm(SR%TRACES(1:SR%NSAMP,I),TRACE,%VAL(SR%NSAMP),%VAL(0))&lt;BR /&gt;&lt;BR /&gt;and for the imported DLL, I used&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;INTERFACE&lt;BR /&gt;Subroutine KECHK32(arg1)&lt;BR /&gt;!DEC$ ATTRIBUTES DLLIMPORT :: KECHK32&lt;BR /&gt;!DEC$ ATTRIBUTES STDCALL, DECORATE, ALIAS:"KECHK32" :: KECHK32&lt;BR /&gt;!DEC$ ATTRIBUTES REFERENCE :: arg1&lt;BR /&gt;!Correctly define the argument types here...&lt;BR /&gt;TYPE SCB ! 80 bytes total., ALIAS:'_KECHK32'&lt;BR /&gt;SEQUENCE&lt;BR /&gt;INTEGER*2 err_code ! 000 Error Code1.&lt;BR /&gt;INTEGER*2 err_status1 ! 002 Error Status 1.&lt;BR /&gt;INTEGER*2 err_status2 ! 004 Error Status 2.&lt;BR /&gt;CHARACTER*1 func_code ! 006 Function Code.&lt;BR /&gt;CHARACTER*5 scb_id ! 007 SCB Identification, s/b "..?Z".&lt;BR /&gt;CHARACTER*9 prod_name ! 012 Product Name (ASCIIZ).&lt;BR /&gt;CHARACTER*3 reserved1 ! 021 Reserved.&lt;BR /&gt;INTEGER*4 prod_serial ! 024 Product Serial Number.&lt;BR /&gt;INTEGER*4 pin ! 028 Product ID Number (PIN).&lt;BR /&gt;INTEGER*2 ecl ! 032 Exec-Count Limit (ECL).&lt;BR /&gt;INTEGER*2 edl ! 034 Expire-Days Limit (EDL).&lt;BR /&gt;CHARACTER*9 expire_date ! 036 Expire-Date (ED) (ASCIIZ).&lt;BR /&gt;CHARACTER*16 user_data ! 045 User-Data.&lt;BR /&gt;CHARACTER*6 rom_serial ! 061 Device ROM Serial#.&lt;BR /&gt;CHARACTER*8 lasered_id ! 067 Device Lasered-ID (LID).&lt;BR /&gt;CHARACTER*5 reserved2 ! 075 Reserved.&lt;BR /&gt;END TYPE SCB&lt;BR /&gt;TYPE (SCB) arg1&lt;BR /&gt;END SUBROUTINE KECHK32&lt;BR /&gt;END INTERFACE&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Calling with&lt;BR /&gt;&lt;BR /&gt;CALL KECHK32(AZBLOCK)&lt;BR /&gt;&lt;BR /&gt;Thanks again,&lt;BR /&gt;&lt;BR /&gt;Charles&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Mar 2011 01:58:24 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixing-C-code-in-a-Fortran-Project/m-p/784000#M29149</guid>
      <dc:creator>chstoyer</dc:creator>
      <dc:date>2011-03-28T01:58:24Z</dc:date>
    </item>
  </channel>
</rss>

