Hybrid development of FORTRAN and C/C ++...

Source: Internet
Author: User
Recently, a FORTRAN Program Modules are integrated into a C ++ platform. For the first time in his life to do Fortran, it is also the first time that we are doing binary hybrid development. To summarize the previous work...

The integration of FORTRAN90 and C ++ can be based on static links. All generate OBJ and link them together. Of course, it can also be a dynamic link. Compile Fortran into a DLL. However
And then call it in C ++ (in windows ...). Of course, this will not be an essential issue. You can choose one based on your needs. In different binary modules, the most important thing is Abi. Description
English and Chinese words cannot be combined in harmony. To play together, some common languages are required...

Calling conventions is important here. Naming
Conventions, Fortran and C ++ function name parsing are often different. You are also named functiona, in C ++ (extern
"C") after compilation, it may be called functiona _. In FORTRAN, it may be called _ functiona @ 4. Of course, this problem is not terrible. Check the compiler's hands.
...

Then there is the issue of stack considerations, that is to say, whether the function stack is managed by the caller or by the caller. If you are interested, you can refer to it here. At the same time, in FORTRAN, parameters are transmitted in different ways by default. By default, parameters are transmitted by addressing...

Finally, the most troublesome problem is argument passing.
Protocol: How should a FORTRAN data be expressed in C ++? The basic data type is okay, but what about the array? What about custom data types? In some high-level languages
Parameters are automatically serialized and deserialized for data conversion. However, for Binary-based interfaces, the basis for calling is the full matching of stacks.
. In FORTRAN, arrays give priority to columns, which is opposite to C ++. What's even worse is that the Fortran array is powerful and can start with any script, and its interval can be any
Meaning, in the Intel compiler, a normal one-dimensional array pointer requires 32 bytes of space. All of these results in parameter passing as the most vulnerable link in such development.
They only rely on the consistency of information in the stack together, a little bit of compiler changes (or use another compiler ...), or changes to the Program Data Structure on both sides (for custom types
...), May lead to the consequences of collapse. To solve this problem, we need to solve it at the design level. Do not use interfaces that need to pass complex structures. Instead, use a series of method calls to replace a single method,
Converts simple data dependencies into interface-defined dependencies. Because the basic data types are always as strong as gold, and the analysis of complex data types is always as unreliable as stocks. Therefore, our principle is to select only simplicity.
Single, not complex...

When you do such a job, the official manual and Examples Code It is your best helper, instead of simply relying on people or Google to solve the problem. Because other people may have problems with you.
Completely consistent, and a little difference may make the results very far. This also shows a way for a person to solve a new problem. For me, I will list all possible means and required materials
As detailed as possible. The difference between bypassing the problem and directly facing the problem is divided into two categories. If you think the price is acceptable, you can do it once and for all.
It is a new problem, and it is usually more difficult to solve and bypass. If you cannot bypass it, sort all your methods in order of reliability. Generally, the source code is always more reliable than the document, and the document has more information than the searched documents.
Reliable. If the reliability measures are the same, you need to consider the simplicity of their implementation, such as reading documents (except for Japanese documents, I have been disgusted ...) it may be simpler than viewing the source code.
Let's take a look at the document. In short, I personally think that reliability is always more important than simplicity. If some means, such as the method simply searched from the Internet, do not implement them first.
After half a day, you find that you have returned to the origin again...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.