<?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 Sending C++ struc and class Recs to a Fortran Subroutine in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Sending-C-struc-and-class-Recs-to-a-Fortran-Subroutine/m-p/793000#M33640</link>
    <description>BIND(C) is supposed to pack structures exactly the way the "corresponding" C compiler (MSVC) does by default. If it doesn't, let us know.</description>
    <pubDate>Tue, 09 Nov 2010 15:40:45 GMT</pubDate>
    <dc:creator>Steven_L_Intel1</dc:creator>
    <dc:date>2010-11-09T15:40:45Z</dc:date>
    <item>
      <title>Sending C++ struc and class Recs to a Fortran Subroutine</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Sending-C-struc-and-class-Recs-to-a-Fortran-Subroutine/m-p/792988#M33628</link>
      <description>&lt;SPAN class="sectionBodyText"&gt;How do I send a c++ class to a fortran subroutine?&lt;BR /&gt;For example&lt;BR /&gt;&lt;BR /&gt;class foo&lt;BR /&gt;{&lt;BR /&gt;public:&lt;BR /&gt; int m_datalen;&lt;BR /&gt; double* m_pfoo_data;&lt;BR /&gt;&lt;BR /&gt; foo(int datalen)&lt;BR /&gt; {&lt;BR /&gt; m_datalen = datalen;&lt;BR /&gt; m_pfoo_data = (double*)_mm_malloc(datalen*sizeof(double),16);&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: x-small;"&gt;&lt;SPAN style="color: #0000ff; font-size: x-small;"&gt;&lt;SPAN style="color: #0000ff; font-size: x-small;"&gt;&lt;SPAN style="color: #0000ff; font-size: x-small;"&gt;&lt;P&gt;&lt;SPAN class="sectionBodyText"&gt;~foo()&lt;/SPAN&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: x-small;"&gt;&lt;SPAN class="sectionBodyText"&gt;{&lt;BR /&gt; _mm_free(m_pfoo_data);&lt;BR /&gt; m_pfoo_data = 0;&lt;BR /&gt; m_datalen = 0&lt;BR /&gt; }&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;SoI want to be able to define a type foo in fortran that can be assigned to a subroutine dummy variable. I understand there is a way to do this using the a common block. &lt;BR /&gt;Thanks.&lt;BR /&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;</description>
      <pubDate>Sat, 06 Nov 2010 17:07:40 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Sending-C-struc-and-class-Recs-to-a-Fortran-Subroutine/m-p/792988#M33628</guid>
      <dc:creator>Frank_M</dc:creator>
      <dc:date>2010-11-06T17:07:40Z</dc:date>
    </item>
    <item>
      <title>Sending C++ struc and class Recs to a Fortran Subroutine</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Sending-C-struc-and-class-Recs-to-a-Fortran-Subroutine/m-p/792989#M33629</link>
      <description>Hi Franck,&lt;BR /&gt;&lt;BR /&gt;Have you tried to simply call the Fortran routine by passing the address of the foo object and defining on the Fortran side a derived type containing the public data like:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE&gt;[fortran]subroutine called_from cpp(dummy_arg)

  implicit none

  type foo
    sequence
    integer(4) datalen
    real(8) m_p_foo(datalen)
  end type

  type (foo) dummy_arg

  ../..

[/fortran]&lt;/PRE&gt; I am not sure that the sequence statement is mantadory but i guess that yes.&lt;BR /&gt;&lt;BR /&gt;I am doing this frequently not from C++ but from Delphi.</description>
      <pubDate>Sun, 07 Nov 2010 14:10:28 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Sending-C-struc-and-class-Recs-to-a-Fortran-Subroutine/m-p/792989#M33629</guid>
      <dc:creator>netphilou31</dc:creator>
      <dc:date>2010-11-07T14:10:28Z</dc:date>
    </item>
    <item>
      <title>Sending C++ struc and class Recs to a Fortran Subroutine</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Sending-C-struc-and-class-Recs-to-a-Fortran-Subroutine/m-p/792990#M33630</link>
      <description>Any reason why the data types and function name shouldn't be set up with iso_c_binding ?&lt;BR /&gt;Yes, if you really want to force a double precision array to an odd alignment, you will require sequence.</description>
      <pubDate>Sun, 07 Nov 2010 15:33:51 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Sending-C-struc-and-class-Recs-to-a-Fortran-Subroutine/m-p/792990#M33630</guid>
      <dc:creator>TimP</dc:creator>
      <dc:date>2010-11-07T15:33:51Z</dc:date>
    </item>
    <item>
      <title>Sending C++ struc and class Recs to a Fortran Subroutine</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Sending-C-struc-and-class-Recs-to-a-Fortran-Subroutine/m-p/792991#M33631</link>
      <description>The C++ struct had an integer (assuming 32-bits) followed by a pointer to doubles and not an array of doubles.&lt;BR /&gt;This is a 8 byte structure on 32-bit platform and 12 byte structure on 64-bit platform.&lt;BR /&gt;&lt;BR /&gt;type foo&lt;BR /&gt; sequence&lt;BR /&gt;integer(4) :: datalen&lt;BR /&gt; integer(C_PTR) :: p_data&lt;BR /&gt;end type foo&lt;BR /&gt;&lt;BR /&gt;Then you need to use something link thesubroutine C_F_POINTER&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN class="kwd" style="color: #007783;"&gt;CALL&lt;/SPAN&gt;&lt;SPAN class="kwd" style="color: #007783;"&gt; C_F_POINTER&lt;/SPAN&gt;&lt;SPAN class="delim" style="color: #007783;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="var" style="color: #007783;"&gt;cptr&lt;/SPAN&gt;&lt;SPAN class="sep" style="color: #007783;"&gt;, &lt;/SPAN&gt;&lt;SPAN class="var" style="color: #007783;"&gt;fptr&lt;/SPAN&gt;&lt;SPAN class="delim" style="color: #007783;"&gt; [&lt;/SPAN&gt;&lt;SPAN class="sep" style="color: #007783;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="kwd" style="color: #007783;"&gt;shape&lt;/SPAN&gt;&lt;SPAN class="delim" style="color: #007783;"&gt;])&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;Jim Dempsey&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 08 Nov 2010 00:15:25 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Sending-C-struc-and-class-Recs-to-a-Fortran-Subroutine/m-p/792991#M33631</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2010-11-08T00:15:25Z</dc:date>
    </item>
    <item>
      <title>Sending C++ struc and class Recs to a Fortran Subroutine</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Sending-C-struc-and-class-Recs-to-a-Fortran-Subroutine/m-p/792992#M33632</link>
      <description>Just take that SEQUENCE out, please, unless you really want to put it in a COMMON. See &lt;A href="http://software.intel.com/en-us/forums/showthread.php?t=78376"&gt;here&lt;/A&gt; for a can of worms it opens. Additionally, reverse the order of attributes: "biggest first" is a good rule of thumb to avoid alignment problems.</description>
      <pubDate>Mon, 08 Nov 2010 09:38:59 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Sending-C-struc-and-class-Recs-to-a-Fortran-Subroutine/m-p/792992#M33632</guid>
      <dc:creator>Jugoslav_Dujic</dc:creator>
      <dc:date>2010-11-08T09:38:59Z</dc:date>
    </item>
    <item>
      <title>Sending C++ struc and class Recs to a Fortran Subroutine</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Sending-C-struc-and-class-Recs-to-a-Fortran-Subroutine/m-p/792993#M33633</link>
      <description>Jugoslav,&lt;BR /&gt;&lt;BR /&gt;The issue you referenced relating to sequence related to pack or not with regard to fields within a record.&lt;BR /&gt;SEQUENCE will perform two functions:&lt;BR /&gt;&lt;BR /&gt;1) sequence the fields in the order written in the source code&lt;BR /&gt;2) pack the fields together.&lt;BR /&gt;&lt;BR /&gt;When the C/C++ record does not use packing, then you may have a problem as expressed in the other thread.&lt;BR /&gt;&lt;BR /&gt;C/C++ orders the fields as written in source code but may pad fields to natural alignments. So you may have interoperability issues between FORTRAN and C/C++ when the struct layouts are not rigidly controlled on both sides.&lt;BR /&gt;&lt;BR /&gt;Without SEQUENCE, the FORTRAN compiler is free to reorganize the order of the variables such to attain the natural alignments with fewer pads.&lt;BR /&gt;&lt;BR /&gt;The safest way, would likely be a combination of SEQUENCE and UNIONs, and additionaly have a conditional compiled option (for both languages) to produce the offsets to the fields on each for use in an ASSERT.&lt;BR /&gt;&lt;BR /&gt;Jim Dempsey&lt;BR /&gt;</description>
      <pubDate>Mon, 08 Nov 2010 14:12:25 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Sending-C-struc-and-class-Recs-to-a-Fortran-Subroutine/m-p/792993#M33633</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2010-11-08T14:12:25Z</dc:date>
    </item>
    <item>
      <title>Sending C++ struc and class Recs to a Fortran Subroutine</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Sending-C-struc-and-class-Recs-to-a-Fortran-Subroutine/m-p/792994#M33634</link>
      <description>&lt;DIV id="tiny_quote"&gt;
                &lt;DIV style="margin-left: 2px; margin-right: 2px;"&gt;Quoting &lt;A rel="/en-us/services/profile/quick_profile.php?is_paid=&amp;amp;user_id=99850" class="basic" href="https://community.intel.com/en-us/profile/99850/"&gt;jimdempseyatthecove&lt;/A&gt;&lt;/DIV&gt;
                &lt;DIV style="background-color: #e5e5e5; padding: 5px; border: 1px inset; margin-left: 2px; margin-right: 2px;"&gt;&lt;I&gt;&lt;BR /&gt;Without SEQUENCE, the FORTRAN compiler is free to reorganize the order of the variables such to attain the natural alignments with fewer pads.&lt;BR /&gt;&lt;/I&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That is correct, but no Fortran compiler in the existing universe actually does that. There are compilers where sequence affects padding though.&lt;/P&gt;&lt;DIV id="tiny_quote"&gt;
                
                &lt;DIV&gt;Quoting &lt;A rel="/en-us/services/profile/quick_profile.php?is_paid=&amp;amp;user_id=99850" class="basic" href="https://community.intel.com/../profile/99850/"&gt;jimdempseyatthecove&lt;/A&gt;&lt;I&gt;&lt;BR /&gt;
&lt;/I&gt;&lt;DIV style="background-color: #e5e5e5; padding: 5px; border: 1px inset; margin-left: 2px; margin-right: 2px;"&gt;&lt;I&gt;The safest way, would likely be a combination of SEQUENCE and 
UNIONs, and additionaly have a conditional compiled option (for both 
languages) to produce the offsets to the fields on each for use in an 
ASSERT.&lt;BR /&gt;&lt;/I&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;P&gt;The safest way is actually to use BIND(C) on the structure, which also prevents the reordering, should the Intel folks change their mind one day. &lt;/P&gt;
&lt;P&gt;&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 08 Nov 2010 16:07:02 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Sending-C-struc-and-class-Recs-to-a-Fortran-Subroutine/m-p/792994#M33634</guid>
      <dc:creator>Jugoslav_Dujic</dc:creator>
      <dc:date>2010-11-08T16:07:02Z</dc:date>
    </item>
    <item>
      <title>Sending C++ struc and class Recs to a Fortran Subroutine</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Sending-C-struc-and-class-Recs-to-a-Fortran-Subroutine/m-p/792995#M33635</link>
      <description>Further comments:&lt;BR /&gt;&lt;BR /&gt;On the C/C++ side always use a packing of 1. This forces you to be cognisant of natural alignment issues within the struct if you want to address alignment for performance. As Jugoslav suggests, placing the larger member variables first generally is recommended. However, this does not resolve all issues. The totalstruct size is also an issue when you have an array of these structs. The conditional compiled option for ASSERT checking member variable offsets within the struct can also be extended to check for natural alignment. Then the asserts can now inform you of missing (required) pads.&lt;BR /&gt;&lt;BR /&gt;&lt;PRE&gt;[cpp]// padd.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "stddef.h"
#include &lt;IOSTREAM&gt;

#pragma pack( push )
#pragma pack( 1 )
__declspec (align(64) )
struct foo_t
{
	__int32	n;
	double	d;
};
#pragma pack( pop )


#define TEST_align(s,m) 
	if(offsetof(s,m)%(sizeof((((foo_t*)0)-&amp;gt;m))))  
	std::cout &amp;lt;&amp;lt; "pad " #s " " #m " " &amp;lt;&amp;lt; (offsetof(s,m)%(sizeof((s*)0)-&amp;gt;m)) &amp;lt;&amp;lt; std::endl;
#if defined(TEST_align)

void aligns_tests()
{
	TEST_align(foo_t, n);
	TEST_align(foo_t, d);
}
#endif

int _tmain(int argc, _TCHAR* argv[])
{
	foo_t	foo;
#if defined(TEST_align)
	aligns_tests();
#endif
	return 0;
}

[/cpp]&lt;/IOSTREAM&gt;&lt;/PRE&gt;&lt;BR /&gt;On x32 platform you will see:&lt;BR /&gt;&lt;BR /&gt; pad foo_t d 4&lt;BR /&gt;&lt;BR /&gt;Jim Dempsey&lt;BR /&gt;</description>
      <pubDate>Mon, 08 Nov 2010 16:10:02 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Sending-C-struc-and-class-Recs-to-a-Fortran-Subroutine/m-p/792995#M33635</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2010-11-08T16:10:02Z</dc:date>
    </item>
    <item>
      <title>Sending C++ struc and class Recs to a Fortran Subroutine</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Sending-C-struc-and-class-Recs-to-a-Fortran-Subroutine/m-p/792996#M33636</link>
      <description>I want to thank everyone for their help.&lt;BR /&gt;The most practical solution for the above example turns out to be&lt;BR /&gt;&lt;BR /&gt;&lt;PRE&gt;[bash]MODULE input_data
    USE, INTRINSIC :: ISO_C_BINDING
    IMPLICIT NONE
    TYPE, BIND(C) :: CData
        INTEGER(C_INT) :: m_datalen
        TYPE(C_PTR) :: m_foo_data
    END TYPE CData
    REAL(8), DIMENSION(:), POINTER :: f_foo_data 
END MODULE input_data

SUBROUTINE FOO_PROCESS(dataRec)
    USE input_data
    IMPLICIT NONE
    TYPE(CData), INTENT(INOUT) :: dataRec
    
    CALL C_F_POINTER(dataRec%m_foo_data, f_foo_data, [dataRec%m_datalen])
       
    RETURN
END SUBROUTINE FOO_PROCESS[/bash]&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Nov 2010 20:42:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Sending-C-struc-and-class-Recs-to-a-Fortran-Subroutine/m-p/792996#M33636</guid>
      <dc:creator>Frank_M</dc:creator>
      <dc:date>2010-11-08T20:42:00Z</dc:date>
    </item>
    <item>
      <title>Sending C++ struc and class Recs to a Fortran Subroutine</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Sending-C-struc-and-class-Recs-to-a-Fortran-Subroutine/m-p/792997#M33637</link>
      <description>Frank,&lt;BR /&gt;&lt;BR /&gt;You haven't shown the C/C++ side of the problem.&lt;BR /&gt;&lt;BR /&gt;The C/C++ struct could be using pack(1) or pack(other), but most likely a pack set by something else preceeding your struct definition.&lt;BR /&gt;&lt;BR /&gt;BIND(C) on the FORTRAN side will not effect your choice of packing on the C/C++ side.&lt;BR /&gt;&lt;BR /&gt;If BIND(C) implies SEQUENCE (with its implicit PACK=1), then the C/C++ side requires explicit packing of 1.&lt;BR /&gt;&lt;BR /&gt;If BIND(C) implies natural alignment with member variables in order specified, then the C/C++ side must also use an alignment attribute such to produce natural aligned membervariables. One cannot assume anything about a default alignment.&lt;BR /&gt;&lt;BR /&gt;Jim Dempsey</description>
      <pubDate>Mon, 08 Nov 2010 23:33:59 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Sending-C-struc-and-class-Recs-to-a-Fortran-Subroutine/m-p/792997#M33637</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2010-11-08T23:33:59Z</dc:date>
    </item>
    <item>
      <title>Sending C++ struc and class Recs to a Fortran Subroutine</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Sending-C-struc-and-class-Recs-to-a-Fortran-Subroutine/m-p/792998#M33638</link>
      <description>BIND(C) implies whatever packing the "companion processor" uses, the processor can be viewed as being the combination of C compiler plus (required/allowed) set of command line switches (or pragmas I guess) that makes the C compiler play ball. Whatever the requirements are, you are one step closer to getting what you want with BIND(C) than you are with SEQUENCE.&lt;BR /&gt;&lt;BR /&gt;Anyway, if you are going to worry about pragma's and command line
switches changing alignment from whatever the C processor used by
default then you need to worry that same variation on the fortran side
too - because that could be changed just as easily.&lt;BR /&gt;&lt;BR /&gt;For my edification: I always thought (possibly erroneously) that byte packing in common (and hence in sequence types) was an implementation detail in the general sense (beyond the requirements for two default reals in a double precision or complex, sizeof logical = integer = real on the second sunday of the month, etc). So if you had a type:&lt;BR /&gt;&lt;BR /&gt;type silly&lt;BR /&gt; sequence&lt;BR /&gt; character(3) :: a&lt;BR /&gt; real :: b&lt;BR /&gt;end type silly&lt;BR /&gt;&lt;BR /&gt;then there could be zero bytes, one byte, or four hundred and three bytes of "padding" in between %a and %b, it just needs to be the same everywhere that sequence of types appears in a storage association context. Or am I deluded?&lt;BR /&gt;&lt;BR /&gt;Not that I use common, and hence not that I use sequence...</description>
      <pubDate>Tue, 09 Nov 2010 01:09:28 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Sending-C-struc-and-class-Recs-to-a-Fortran-Subroutine/m-p/792998#M33638</guid>
      <dc:creator>IanH</dc:creator>
      <dc:date>2010-11-09T01:09:28Z</dc:date>
    </item>
    <item>
      <title>Sending C++ struc and class Recs to a Fortran Subroutine</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Sending-C-struc-and-class-Recs-to-a-Fortran-Subroutine/m-p/792999#M33639</link>
      <description>type silly&lt;BR /&gt; sequence&lt;BR /&gt; character(3) :: a&lt;BR /&gt; real :: b&lt;BR /&gt;end type silly&lt;BR /&gt;&lt;BR /&gt;I believe the above would be called a "character sequence type" and b would start at the 4th byte of the type.&lt;BR /&gt;Equivilent to:&lt;BR /&gt;&lt;BR /&gt;#pragma pack(1)&lt;BR /&gt;struct&lt;BR /&gt;{&lt;BR /&gt; char a[3];&lt;BR /&gt; float b;&lt;BR /&gt;};&lt;BR /&gt;&lt;BR /&gt;Note, the FORTRAN programmer should refrain from using "REAL" as this leaves an ambiguity as to the format. Use REAL(4) or better REAL(C_FLOAT).&lt;BR /&gt;&lt;BR /&gt;use, intrinsic :: ISO_C_BINDING&lt;BR /&gt;...&lt;BR /&gt;type, bind(C) ::silly&lt;BR /&gt; sequence&lt;BR /&gt; character(3) :: a&lt;BR /&gt; real(C_FLOAT) :: b&lt;BR /&gt;end type silly&lt;BR /&gt;----------------&lt;BR /&gt;#pragma pack(push)&lt;BR /&gt;#pragma pack(1)&lt;BR /&gt;struct silly&lt;BR /&gt;{&lt;BR /&gt; char a[3];&lt;BR /&gt; float b;&lt;BR /&gt;};&lt;BR /&gt;#pragma pack(pop)&lt;BR /&gt;&lt;BR /&gt;============= or ===========&lt;BR /&gt;&lt;BR /&gt;use, intrinsic :: ISO_C_BINDING&lt;BR /&gt;...&lt;BR /&gt;type, bind(C) ::notsilly&lt;BR /&gt; character(3) :: a&lt;BR /&gt; real(C_FLOAT) :: b&lt;BR /&gt;end type notsilly&lt;BR /&gt;----------------&lt;BR /&gt;#pragma pack(push)&lt;BR /&gt;#pragma pack(8)&lt;BR /&gt;struct notsilly&lt;BR /&gt;{&lt;BR /&gt; char a[3];&lt;BR /&gt; float b;&lt;BR /&gt;};&lt;BR /&gt;#pragma pack(pop)&lt;BR /&gt;&lt;BR /&gt;****&lt;BR /&gt;MS uses default packing of 8 meaning the alignment of a member will be on a boundary that is either a multiple of &lt;I&gt;n&lt;/I&gt; or a multiple of the size of the member, whichever is smaller.&lt;BR /&gt;&lt;BR /&gt;The programmer should not assume anything about the packing. Any of the 100's, 1000'sof include files could alter the packing from that observed by a "Hello World" example probram.&lt;BR /&gt;&lt;BR /&gt;Now as to if FORTRAN uses the packing of 8 or not with BIND(C) I cannot say. Steve might be able to answer this.&lt;BR /&gt;&lt;BR /&gt;Jim Dempsey&lt;BR /&gt;</description>
      <pubDate>Tue, 09 Nov 2010 15:31:13 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Sending-C-struc-and-class-Recs-to-a-Fortran-Subroutine/m-p/792999#M33639</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2010-11-09T15:31:13Z</dc:date>
    </item>
    <item>
      <title>Sending C++ struc and class Recs to a Fortran Subroutine</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Sending-C-struc-and-class-Recs-to-a-Fortran-Subroutine/m-p/793000#M33640</link>
      <description>BIND(C) is supposed to pack structures exactly the way the "corresponding" C compiler (MSVC) does by default. If it doesn't, let us know.</description>
      <pubDate>Tue, 09 Nov 2010 15:40:45 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Sending-C-struc-and-class-Recs-to-a-Fortran-Subroutine/m-p/793000#M33640</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2010-11-09T15:40:45Z</dc:date>
    </item>
    <item>
      <title>Sending C++ struc and class Recs to a Fortran Subroutine</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Sending-C-struc-and-class-Recs-to-a-Fortran-Subroutine/m-p/793001#M33641</link>
      <description>&lt;DIV id="tiny_quote"&gt;&lt;DIV style="margin-left: 2px; margin-right: 2px;"&gt;Quoting &lt;A jquery1289340079462="63" 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;BIND(C) is supposed to pack structures exactly the way the "corresponding" C compiler (MSVC) does by default. If it doesn't, let us know.&lt;/I&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;BR /&gt;The "gotcha" I am stressing is if you include any header files, and/or use any command line options affecting packing you are &lt;EM&gt;never&lt;/EM&gt; assured of getting default packing. It is very unusual that any C/C++ application calling FORTRAN support subroutines/functions would NOT contain #include "...".&lt;BR /&gt;&lt;BR /&gt;Therefore, I urge you to explicitly specify the packing for the structs passed to FORTRAN. Your source code is not in control of contents of include files nor of command line. So assume:&lt;BR /&gt;&lt;BR /&gt;If you do not declare packing, expect problems (sooner or later).&lt;BR /&gt;&lt;BR /&gt;Same thing with assumption of size of int, INTEGER, long,REAL, LOGICAL, bool, and what happens with unsigned, etc...&lt;BR /&gt;&lt;BR /&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Tue, 09 Nov 2010 22:12:21 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Sending-C-struc-and-class-Recs-to-a-Fortran-Subroutine/m-p/793001#M33641</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2010-11-09T22:12:21Z</dc:date>
    </item>
    <item>
      <title>Sending C++ struc and class Recs to a Fortran Subroutine</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Sending-C-struc-and-class-Recs-to-a-Fortran-Subroutine/m-p/793002#M33642</link>
      <description>I understand what you are saying, but your gotcha applies to the fortran code that uses SEQUENCE as well. For example, the following little snippet, when compiled and run with 11.1.067 with /warn:all /check:all command line on ia32 indicates byte packing for the sequence type (and an appropriate compile time warning about alignment). Add /align to the command line and you'll get four byte alignment. Compile it with gfortran (without anything special on the command line) and you'll get four byte alignment (which I guess answers my question about what sequence requires). Even putting !DEC$ PACK graffitti all through your code won't necessarily help with the last one (similarly it is also conceivable that a C compiler might exist that doesn't understand #pragma pack and will just ignore it, but far less likely I guess).&lt;BR /&gt;&lt;BR /&gt;BIND(C) at least avoids half of the problem, though I'm not sure which half... &lt;BR /&gt;&lt;BR /&gt;&lt;PRE&gt;[fortran]PROGRAM but_my_stars_never_align
  USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_CHAR, C_FLOAT  
  IMPLICIT NONE

  TYPE seq_type
    SEQUENCE
    CHARACTER(9) :: a
    REAL :: b
  END TYPE seq_type  
  TYPE(seq_type) :: sqt
  
  TYPE, BIND(C) :: bindc_type
    CHARACTER(LEN=9,KIND=C_CHAR) :: a
    REAL(C_FLOAT) :: b
  END TYPE bindc_type
  TYPE(bindc_type) :: bct
  
  ! If your computer has more bits than mine, then make this Z16.16.
  CHARACTER(*), PARAMETER :: fmt = "(A,': ',99(Z8.8,:,','))"
  
  !****
  
  PRINT fmt, 'sequence: ', LOC(sqt), LOC(sqt%a), LOC(sqt%b)
  PRINT fmt, 'bind(c):  ', LOC(bct), LOC(bct%a), LOC(bct%b)

END PROGRAM but_my_stars_never_align

[/fortran]&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Nov 2010 04:39:26 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Sending-C-struc-and-class-Recs-to-a-Fortran-Subroutine/m-p/793002#M33642</guid>
      <dc:creator>IanH</dc:creator>
      <dc:date>2010-11-10T04:39:26Z</dc:date>
    </item>
    <item>
      <title>Sending C++ struc and class Recs to a Fortran Subroutine</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Sending-C-struc-and-class-Recs-to-a-Fortran-Subroutine/m-p/793003#M33643</link>
      <description>&lt;DIV id="tiny_quote"&gt;
                &lt;DIV style="margin-left: 2px; margin-right: 2px;"&gt;Quoting &lt;A rel="/en-us/services/profile/quick_profile.php?is_paid=&amp;amp;user_id=99850" class="basic" href="https://community.intel.com/en-us/profile/99850/"&gt;jimdempseyatthecove&lt;/A&gt;&lt;/DIV&gt;
                &lt;DIV style="background-color: #e5e5e5; padding: 5px; border: 1px inset; margin-left: 2px; margin-right: 2px;"&gt;&lt;I&gt;&lt;BR /&gt;On the C/C++ side always use a packing of 1. This forces you to be cognisant of natural alignment issues within the struct if you want to address alignment for performance.&lt;BR /&gt;&lt;/I&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I understand where you're coming from Jim, but if I may use a Buddhist metaphor, that approach reminds me of wearing a pebble in your shoe in order to be cognisant that suffering exists in this world. I prefer using the tools designed to do the job, and letting the compiler do its part of the job, not worrying about every gory implementation detail.&lt;/P&gt;&lt;P&gt;In a similar mindset, I don't expect that a randomly included, badly written header/include file affects alignment in my code. Should that happen, I would have a word with the author of that code (or ditch it through the window if it's 3rd party). But we can't -- and should not -- protect ourselves against every possible error or blunder in the tools of our environment (3rd party compilers, libraries, header files, hardware, you name it).&lt;/P&gt;</description>
      <pubDate>Wed, 10 Nov 2010 08:29:07 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Sending-C-struc-and-class-Recs-to-a-Fortran-Subroutine/m-p/793003#M33643</guid>
      <dc:creator>Jugoslav_Dujic</dc:creator>
      <dc:date>2010-11-10T08:29:07Z</dc:date>
    </item>
  </channel>
</rss>

